1

我想知道有没有一种方法可以使图例垂直滚动。这样做的原因是我在一个图表上的线条太多,无法将它们显示在具有良好可读大小字体的固定图例上。

我需要将所有图保留在一个图表上,因此减少线数不是一种选择。

或者/另外,当用户将光标悬停在一行上时,有没有一种方法可以显示该行的标签?

我目前有一些这样的代码:

ax.plot(xv, yv, 'o-', label="\n".join(textwrap.wrap(temp[0][i][0],120)), picker=1)

handles, labels = ax.get_legend_handles_labels()
xticks = [i for i in range(0,40)]
yticks = [i for i in range(0,105,5)]
minorLocator   = AutoMinorLocator()

# Shink current axis by 20%
box = ax.get_position()
ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])

# Put a legend to the right of the current axis
ax.legend(handles, labels, loc='center left', bbox_to_anchor=(1, 0.5), prop = fontP)

#ax.legend(handles, labels, "center")
#ax.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
#ax.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3, ncol=2, mode="expand", borderaxespad=0.)

plt.xticks(xticks)
plt.yticks(yticks)

ax.yaxis.set_minor_locator(minorLocator)
plt.tick_params(which='minor', length=4, color='r')
ax.yaxis.grid(True, which='minor')

plt.xlabel('Hour')
plt.ylabel('Frequency')
plt.grid(True, axis = 'both')

plt.show()

谢谢你的帮助!

4

0 回答 0