-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Bug]: inset colorbar colours and frame misaligned #29383
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
Comments
We can also reproduce without figsize=(6.4, 4.807), dpi=100 Note that the Agg renderer rounds down with
|
Is this a rounding vs. truncating issue? It may be that we are not consistent with that. |
The problem goes away with the following, which makes the vector renderer use the same size in inches as Agg used. diff --git a/lib/matplotlib/backends/backend_mixed.py b/lib/matplotlib/backends/backend_mixed.py
index ea8f50a39a..234954bbfc 100644
--- a/lib/matplotlib/backends/backend_mixed.py
+++ b/lib/matplotlib/backends/backend_mixed.py
@@ -76,8 +76,14 @@ class MixedModeRenderer:
# change the dpi of the figure temporarily.
self.figure.dpi = self.dpi
+ width_pixels = int(self._width * self.dpi)
+ height_pixels = int(self._height * self.dpi)
+
+ self._width = width_pixels / self.dpi
+ self._height = height_pixels / self.dpi
+
self._raster_renderer = self._raster_renderer_class(
- self._width*self.dpi, self._height*self.dpi, self.dpi)
+ width_pixels, height_pixels, self.dpi)
self._renderer = self._raster_renderer
if self._bbox_inches_restore: # when tight bbox is used
This causes three image test failures, but they all look like improvements: test_bbox_inches_tight_raster (pdf and svg) goes from to Easier to see when flicking between the two in a viewer, but the blue line now looks better aligned in the corners. test_bbox_inches_inset_rasterized goes from I am too far out of my depth to say whether this is actually the correct fix! |
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 usingAxes.inset_axes
.Code for reproduction
From #27763 (comment):
Actual outcome
Expected outcome
Colorbar frame should be lined up with its colours.
Additional information
To reproduce the bug we need
inset_axes
bbox_inches='tight'
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
The text was updated successfully, but these errors were encountered: