python - Multiple y axis using matplotlib not working -


i have used following code plot graph using matplotlib 4 parameter x=depth, y1=temp, y2=salinity, y3=velocity value of velocity not display , 2nd , 3rd axes not adjustable(scale value) 1st when zoom has constant scale value, how make adjustable(scale value) ,i mean scale value variable axes when zoom in zoomout.

 mpl_toolkits.axes_grid1 import host_subplot  import mpl_toolkits.axisartist aa  import matplotlib.pyplot plt  import numpy np   if 1:      host = host_subplot(111, axes_class=aa.axes)     plt.subplots_adjust(right=0.75)      par1 = host.twinx()     par2 = host.twinx()      offset = 60     new_fixed_axis = par2.get_grid_helper().new_fixed_axis     par2.axis["right"] = new_fixed_axis(loc="right", axes=par2, offset=       (offset, 0))      par2.axis["right"].toggle(all=true)     # host.set_xlim(0, 2)     #host.set_ylim(0, 2)      host.set_xlabel("depth")     host.set_ylabel("temperature")     par1.set_ylabel("salinity")     par2.set_ylabel("velocity")     x  = np.array([0,5,10,15,20,25,30,35])     y1 = np.array([30.340,30.080,29.116,28.395,28.093,28.040,27.975,27.872])     y2 = np.array([33.130,34.046,35.119,34.933,34.764,34.824,34.860,34.852])     y3 = np.array([1544.296, 1544.787, 1543.452,1542.280,1541.522,1544.548,1541.523,1541.368])      p1, = host.plot(x, y1, label="temperature")     p2, = par1.plot(x, y2, label="salinity")     p3, = par2.plot(x, y3, label="velocity")      #par1.set_ylim(0, 4)     #par2.set_ylim(1, 65)      host.legend()      host.axis["left"].label.set_color(p1.get_color())     par1.axis["right"].label.set_color(p2.get_color())     par2.axis["right"].label.set_color(p3.get_color())      plt.draw()     plt.show() 

here example works way suggest: http://matplotlib.org/examples/pylab_examples/multiple_yaxis_with_spines.html

basically, avoid using "new_fixed_axis" function:

from mpl_toolkits.axes_grid1 import host_subplot import mpl_toolkits.axisartist aa import matplotlib.pyplot plt import numpy np  fig,host = plt.subplots() fig.subplots_adjust(right=0.75)  par1 = host.twinx()  par2 = host.twinx()  par2.spines["right"].set_position(("axes", 1.2)) par2.spines["right"].set_visible(true)  host.set_xlabel("depth") host.set_ylabel("temperature") par1.set_ylabel("salinity") par2.set_ylabel("velocity")  x  = np.array([0,5,10,15,20,25,30,35]) y1 = np.array([30.340,30.080,29.116,28.395,28.093,28.040,27.975,27.872]) y2 = np.array([33.130,34.046,35.119,34.933,34.764,34.824,34.860,34.852]) y3 = np.array([1544.296, 1544.787, 1543.452,1542.280,1541.522,1544.548,1541.523,1541.368])  p1, = host.plot(x, y1, 'b', label="temperature") p2, = par1.plot(x, y2, 'r', label="salinity") p3, = par2.plot(x, y3/10, 'g', label="velocity/00")  host.yaxis.label.set_color(p1.get_color()) par1.yaxis.label.set_color(p2.get_color()) par2.yaxis.label.set_color(p3.get_color())  tkw = dict(size=4, width=1.5) host.tick_params(axis='y', colors=p1.get_color(), **tkw) par1.tick_params(axis='y', colors=p2.get_color(), **tkw) par2.tick_params(axis='y', colors=p3.get_color(), **tkw) host.tick_params(axis='x', **tkw)  host.legend() plt.show() 

there still little problem weird y-axis scales, @ least zoom+pan :).

enter image description here


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -