I try to plot some curves with matplotlib using the default gui component and have some trouble to select which of the two y-axes that the mouse over functionality should select. The default case seems开发者_运维问答 to be that ax2 gets selected but I would like to use ax1 instead. Is this possible to fix in some easy way?
This is the code I use at the moment to plot my curves.
Best regards Anders Olme
delta=np.median(np.diff(measurementvalues.measvalues))
myscale=10
myrange=(measurementvalues.lowerlimit - delta*myscale, measurementvalues.upperlimit + delta*myscale)
figure = plt.figure()
ax1 = figure.add_subplot(111)
(n, bins, patches) = ax1.hist(measurementvalues.measvalues, 10, range=myrange, normed=0, facecolor='green', alpha=0.75)
ax2 = ax1.twinx()
mean = np.average(measurementvalues.measvalues)
sigma = np.std(measurementvalues.measvalues)
y = mlab.normpdf(bins, mean, sigma)
ax2.plot(bins, y, 'r-', linewidth=1)
ax1.set_xlabel('Measvlues')
ax2.set_ylabel('Probability')
ax1.set_title(r'$\mathrm{Histogram\ of\ measvalues:}\ \mu=$'+str(mean)+r'$,\ \sigma=$'+str(sigma)+r'$$')
plt.grid(True)
plt.show()
Add the following after calling twinx
ax3 = ax1.figure.add_axes(ax1.get_position(True), sharex=ax1, sharey=ax1,
frameon=False)
ax3.xaxis.set_visible(False)
ax3.yaxis.set_visible(False)
You will also need to change plt.grid(True) to ax1.grid(True)
精彩评论