python - matplotlib: Aligning twin y-axes -


the answer question suggests play around set_ylim/get_ylim in order align 2 twin axes. however, not seem working out me.

code snippet:

fig, ax1 = plt.subplots()  ylim = [miny, maxy] xlim = [0, 0.01]  x in analysisnumbers:     ax1.plot(getdata(x), vcoords, **getstyle(x))  ax1.set_yticks(vcoords) ax1.grid(true, which='major')   ax2 = ax1.twinx() ax2.set_yticks(ax1.get_yticks()) ax2.set_ylim(ax1.get_ylim()) ax2.set_ylim(ax1.get_ylim())  plt.xlim(xlim[0], xlim[1]) plt.ylim(ylim[0], ylim[1])  plt.minorticks_on()  plt.show() 

graph output (open image in new window):

enter image description here

the twin axes should same, not. labels same, alignment not (see zeroes not line up). what's wrong?

as tcaswell points out in comment, plt.ylim() affects 1 of axes. if replace these lines:

ax2.set_ylim(ax1.get_ylim()) ax2.set_ylim(ax1.get_ylim())  plt.xlim(xlim[0], xlim[1]) plt.ylim(ylim[0], ylim[1]) 

with this:

ax1.set_ylim(ylim[0], ylim[1]) ax2.set_ylim(ax1.get_ylim())  plt.xlim(xlim[0], xlim[1]) 

it'll work i'm guessing intended.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -