Matplotlib dual zoom mouse

I am trying to plot some curves using matplotlib using the default gui component and you have a specific problem to choose which of the two y-axes to select with the mouse. The situation with the position seems to be that ax2 is selected, but instead I would like to use ax1. Can this be fixed in some simple way?

This is the code I'm currently using 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() 
+4
source share
1 answer

Add after calling doublex

following:
 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)

+2
source

Source: https://habr.com/ru/post/1299242/


All Articles