-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Open
Description
Bug summary
Following #29340, when a colorbar is added in an inset axes there is still a small mismatch between the frame and the colours of the colorbar, as shown in the test image added at #29340. That test uses the toolkits inset_axes
but the problem also appears when using Axes.inset_axes
.
Code for reproduction
From #27763 (comment):
import matplotlib.pyplot as plt
import numpy as np
fig, axes = plt.subplots(1, 1, layout='constrained')
x = np.random.randint(100, size=(30, 200))
c = axes.imshow(x, origin='lower', cmap='Reds', aspect=1)
axins1 = axes.inset_axes([0.05, 0.8, 0.2, 0.09])
fig.colorbar(c, cax=axins1, orientation="horizontal")
fig.savefig('test_single.pdf', bbox_inches='tight')
Actual outcome
Expected outcome
Colorbar frame should be lined up with its colours.
Additional information
To reproduce the bug we need
- Rasterized artist in
inset_axes
- Saving with
bbox_inches='tight'
- Saving as pdf, so perhaps linked to the mixed-mode renderer calling
adjust_bbox
multiple times viaprocess_figure_for_rasterizing
.
Increasing the figure dpi to 300 makes the problem disappear. Also, when I originally wrote the test at #29340 I forgot to set the style. The problem did not show up with classic mode.
I have reproduced with v3.2, so probably this never worked.
Operating system
Ubuntu
Matplotlib Version
main
Matplotlib Backend
QtAgg
Python version
3.12.5
Jupyter version
n/a
Installation
git checkout