Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

colorbar might shrink plots if used with twinx #8823

Closed
Milestone
@PrometheusPi

Description

@PrometheusPi

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

misaligned_twinx_wrong

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

misaligned_twinx_correct

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp