Description
Bug report
Bug summary
With multiple subplots with one of them being a color plot with colorbar()
, png backends emits significantly different image from everything else (qt5, pdf, svg). This was not the case in 3.2.2.
Code for reproduction
import matplotlib
from matplotlib.pyplot import *
import numpy as np
matplotlib.rcParams['font.size'] = 20
matplotlib.rc('xtick', labelsize=15)
matplotlib.rc('ytick', labelsize=15)
figure(figsize=[12.6, 11.2])
subplot(2, 2, 1)
xlabel("XXX XXX")
ylabel("YYY YYY")
title("Title Title")
subplot(2, 2, 2)
xlabel("XXX XXX")
ylabel("YYY YYY")
title("Title Title")
subplot(2, 2, 3)
xlabel("XXX XXX")
ylabel("YYY YYY")
title("Title Title")
subplot(2, 2, 4)
def func3(x, y):
return (1 - x / 2 + x**5 + y**3) * np.exp(-(x**2 + y**2))
dx, dy = 0.05, 0.05
x = np.arange(-3.0, 3.0, dx)
y = np.arange(-3.0, 3.0, dy)
X, Y = np.meshgrid(x, y)
Z2 = func3(X, Y)
imshow(Z2)
xlabel("XXX XXX")
ylabel("YYY YYY")
title("Title Title")
colorbar() # <-- This is the main trigger of the bug
tight_layout(pad=0.6)
savefig("b.pdf", bbox_inches="tight", transparent=True,
metadata={'Creator': None, 'Producer': None, "CreationData": None})
savefig("b.png", bbox_inches="tight", transparent=True)
Actual outcome
The issue manefest itself different if the setting of font.size
, x/ytick size, or the tight_layout
was removed but in all cases the png backends produces different results than other backend. With the code as posted, which is the most similar to what I actually have in my real code that worked on 3.2.2, the png output was.
whereas the pdf output (converted to png) and everything else was,
The difference in this case is the overlapping of the title/labels and this should have been fixed by the tight_layout
. With other options (e.g. if some of the font size settings are commented out) the png image will come out clipped.
Expected outcome
The png output should be the same as the pdf output as it was on 3.2.2.
Matplotlib version
- Operating system: ArchLinux
- Matplotlib version: 3.3.0
- Matplotlib backend (
print(matplotlib.get_backend())
):Qt5Agg
- Python version: 3.8.3
matplotlib installed from ArchLinux repo.