Skip to content

[Bug]: 3.5.0 colorbar outside of its axis when saved into vectorial formats #21672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cgadal opened this issue Nov 18, 2021 · 1 comment
Closed

Comments

@cgadal
Copy link
Contributor

cgadal commented Nov 18, 2021

Bug summary

For some figure/subplot/colorbar axis aspect ratios, the colorbar is outside of its axes when saved into vectorial formats (pdf, svg).

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 100, 100)
y = np.linspace(0, 100, 100)
z = x[None, :]**2 + y[:, None]**2

fig, axarr = plt.subplots(1, 2, figsize=(3, 2.8789385625),
                          constrained_layout=True, sharey=True)
ax = axarr[0]
a = ax.pcolormesh(x, y, z, snap=True)
fig.colorbar(a, ax=ax, location='top')
#
ax = axarr[1]
a = ax.pcolormesh(x, y, z, snap=True)
fig.colorbar(a, ax=ax, location='top')
plt.savefig('test_colorbar.pdf')
plt.savefig('test_colorbar.svg')
plt.savefig('test_colorbar.png', dpi=800)

Actual outcome

Screenshot from 2021-11-18 17-01-03

Expected outcome

The colorbar should be within its axis, and not shifted upward.

Additional information

  • It does not occur when the figure is saved to non-vectorial format (i.e png, etc ..)
  • In this case, it does not occur for all figure aspect ratios.
  • It was already the case in matplotlib 3.4.3

Operating system

Ubuntu 20

Matplotlib Version

3.5.0

Matplotlib Backend

QtAgg

Python version

3.8.10

Jupyter version

No response

Installation

pip

@cgadal cgadal changed the title [Bug]: 3.5.0 colorbar outside of its axes when saved into vectorial formats [Bug]: 3.5.0 colorbar outside of its axis when saved into vectorial formats Nov 18, 2021
@jklymak
Copy link
Member

jklymak commented Nov 18, 2021

Yes, this is very old #6827 @brunobeltran fixed it, but his PR has languished #17182

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants