0

在我的程序中,我在 matplotlib 图上使用 mplcursors,这样我就可以精确地识别某些点。

mplcursors.cursor(multiple=True).connect("add", lambda sel: sel.annotation.draggable(False))

现在我制作了一个多轴的复杂图形:

first = 1
offset = 60

for x in range(len(cat_list)):
    if "Time" not in cat_list[x]:
        if first and not cat_list[x].startswith("EngineSpeed"):

            parasites[x] = ParasiteAxes(host, sharex = host)
            host.parasites.append(parasites[x])
            parasites[x].axis["right"].set_visible(True)
            parasites[x].set_ylabel(cat_list[x])
            parasites[x].axis["right"].major_ticklabels.set_visible(True)
            parasites[x].axis["right"].label.set_visible(True)
            p_plot, = parasites[x].plot(t, t_num_list[x], label = cat_list[x])
            #parasites[x].axis["right"+str(x+1)].label.set_color(p_plot.get_color())
            parasites[x].axis["right"].label.set_color(p_plot.get_color())
            first = 0

        elif not cat_list[x].startswith("EngineSpeed"):

            parasites[x] = ParasiteAxes(host, sharex = host)
            host.parasites.append(parasites[x])
            parasites[x].set_ylabel(cat_list[x])
            new_axisline = parasites[x].get_grid_helper().new_fixed_axis
            parasites[x].axis["right"+str(x+1)] = new_axisline(loc = "right",
            axes = parasites[x],
            offset = (offset, 0))
            p_plot, = parasites[x].plot(t, t_num_list[x])
            parasites[x].axis["right"+str(x+1)].label.set_color(p_plot.get_color())
            offset = offset + 60
            host.legend()

fig.add_axes(host)
plt.show()

此代码产生下图:

https://i.stack.imgur.com/Wl7yC.png

现在我必须以某种方式通过选择使用哪个轴来选择某些点。如何制作用于选择活动轴的选择菜单,然后如何使用 mplcursors 选择我的点?

谢谢,齐加

4

0 回答 0