ここにpyplot.barhの例があります。ユーザーが赤色または緑色のバーをクリックすると、スクリプトはx &のy値を取得するはずです。したがって、図のpick_eventを追加します。 barplに対してmatplotlib pick_eventは機能しませんか?
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
# Random data
bottom10 = pd.DataFrame({'amount':-np.sort(np.random.rand(10))})
top10 = pd.DataFrame({'amount':np.sort(np.random.rand(10))[::-1]})
# Create figure and axes for top10
fig,axt = plt.subplots(1)
# Plot top10 on axt
top10.plot.barh(color='red',edgecolor='k',align='edge',ax=axt,legend=False)
# Create twin axes
axb = axt.twiny()
# Plot bottom10 on axb
bottom10.plot.barh(color='green',edgecolor='k',align='edge',ax=axb,legend=False)
# Set some sensible axes limits
axt.set_xlim(0,1.5)
axb.set_xlim(-1.5,0)
# Add some axes labels
axt.set_ylabel('Best items')
axb.set_ylabel('Worst items')
# Need to manually move axb label to right hand side
axb.yaxis.set_label_position('right')
#add event handle
def onpick(event):
thisline = event.artist
xdata = thisline.get_xdata()
ydata = thisline.get_ydata()
ind = event.ind
print 'onpick points:', zip(xdata[ind], ydata[ind])
fig.canvas.mpl_connect('pick_event', onpick)
plt.show()
しかし、何も私はカラーバーをクリックしたときに起こりました。なぜそれは反応がないのですか?
Greate!それで、魔法はプロット時にargv 'picker = True'を追加しています。しかし、私の場合は、完全ではありません。双軸(axb = axt.twiny())を使用しているので、 )それは双軸の働きです。 – dindom