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

Surprising alignment of (multiple) colorbars with constrained layout active #10627

Closed
Labels
topic: geometry managerLayoutEngine, Constrained layout, Tight layout
Milestone
@afvincent

Description

@afvincent

Bug report

Bug summary

The new experimental layout manager seems to produce a rather surprising alignment of two colorbars when one is shared by severalAxes instances, and another one is simply stealing space from a singleAxes instance. It seems like@jklymak might have a fix in mind, but he also have a day-job ^^: milestoning for 2.2 just in case he manages to have a shot in time for it.

NB: originally fromGitter.

Code for reproduction

importmatplotlib.pyplotaspltimportnumpyasnp# Dummy dataarr_shape= (64,256)vmin,vmax=80.0,120.0arr_A=np.random.uniform(low=vmin,high=vmax,size=arr_shape)arr_B=np.random.uniform(low=vmin,high=vmax,size=arr_shape)rel_error=100* (arr_A-arr_B)/arr_A# Plotting time!fig,axs=plt.subplots(3,1,constrained_layout=True)# Raw data arrays, with a shared colorbarforax,arr,lblin ((axs[0],arr_A,"Case A"), (axs[1],arr_B,"Case B")):_im0=ax.imshow(arr,vmin=vmin,vmax=vmax)ax.set_title(lbl)fig.colorbar(_im0,ax=axs[:2],label="Raw Data (a.u.)",aspect=2*20,pad=-12)# Relative difference at the bottom, with its own colorbarax=axs[2]_im1=ax.imshow(rel_error,cmap="coolwarm",vmin=min(rel_error.min(),-rel_error.max()),vmax=max(rel_error.max(),-rel_error.min()))ax.set_title("(A - B) / A")fig.colorbar(_im1,ax=axs[2],label="Difference (%)",aspect=20)# Cosmeticksforaxinaxs.flat:ax.set_xticks([])ax.set_yticks([])plt.show()

@jklymak I know, I know, it is not really “minimal”, but I was originally planning to show a use case rather than a MWE. And at least, it is a standalone example 😈.

Actual outcome

constrained_multi_cbars

Expected outcome

Something closer to
constrained_multi_cbars_workaround

Workaround
The figure in theExpected outcome section was produced by passing the supplementary parameter “pad=-12” in the relevant line:

fig.colorbar(_im0,ax=axs[:2],label="Raw Data (a.u.)",aspect=2*20,pad=-12)

Matplotlib version

  • Operating system: Linux (Fedora 27)
  • Matplotlib version: 2.2.0rc1 from conda
  • Python version: 3.6 from conda

Edit: English

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: geometry managerLayoutEngine, Constrained layout, Tight layout

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp