Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.1k
Description
Bug report
Changing plot alignment for different placing of colorbar() in twinx plot
If one combines apcolormesh plot/hist2d plot with a standardplot by usingtwinx, the graph from theplot moves to wrong x values if the colorbar is called after theplot call. If it is called before, the alignment is fine.
I am not sure if this is a bug or just wrong usage.
However, one of the resulting graphs has a wrong extent that might lead to misinterpretations.
Code for reproduction
importnumpyasnpimportmatplotlib.pyplotaspltdata=np.random.random((64,128))*2.0x=np.arange(128)y=np.arange(64)plt.pcolormesh(x,y,data)#plt.colorbar() --> here it works fineplt.twinx()plt.colorbar()# --> here it gives wrong x values for the orange plotplt.plot(x,np.sin(x/10),color="orange",lw=4)plt.show()
Actual outcome
Next to the confusing layout the plot shows actually a wrong graph:
theorange plot just goes to around x=100 butshould go to x=128.
(The axis of the colorbar is correct and shows the range ofdata.)
Expected outcome
Ifcolorbar is called beforetwinx, the orange graph has the correct extent.
I am not sure if this is a bug or a wrong usage of matplotlib. In any case the wrong extent of the (in this case) orange plot is a dangerous behavior that might lead to misinterpretations of the data.
Matplotlib version
- Operating System: Ubuntu 14.04.1
- Matplotlib Version: 2.0.0rc1
- Python Version: 3.4.3
- Jupyter Version: 1.0.0 (I am using
%matplotlib inline) - Other Libraries: numpy 1.12.0b1
I installed matplotlib via pip.

