python - Matplotlib axes autoscale does not work with after twinx() -
i have found can not axes autoscale work on 1st axes after creating second axes using twinx. expected?
import numpy np import matplotlib.pyplot plt x = np.arange(0, 10, 0.1) y1 = 0.05 * x**2 y2 = -1 *y1 fig, axl = plt.subplots() # make left axes axr = axl.twinx() # make left axes axl.plot(x, y1, 'g-') # plot on left axl.grid() axl.autoscale(enable=true, axis=u'both', tight=false) plt.show() # stuff later plot on axr
when run above code autoscales in y-direction correctly on left axes (0 5) changes x-axis scale +/- 0.06 instead of correct 0 10. however, once axr no longer blank , plotted on axr behaves expect.
this example first came across issue in more complicated pyqt4 gui allows user create multiple subplots & left/right combinations. since user 1 manually controlling plot creation order possible above situation present itself.
is there way autoscale work blank twinx right axes. or xlimit going have manually set?
fyi, using python 3.4 part of anaconda v2.0.1 matplotlib v1.3.1
thanks.
this merely workaround proper solution or explanation.
simply add invisible point in right axes not empty:
axr.plot(0, 0, visible=false)
you have make sure though, invisible point lies within ranges of data plot in axl
. e.g.:
axr.plot(np.mean(x),np.mean(y1),visible=false)
as explanation (i'm guessing):
axr.datalim
[-np.inf, np.inf]
initially. union of axr.datalim
, axl.datalim
still gives [-np.inf, np.inf]
collapsed [0,0]
.
edit: fixed (here). upgrading matplotlib v1.4.* should solve problem.
Comments
Post a Comment