-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
FIX: dpi and scatter for subfigures now correct #20777
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
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
e2103dd
to
6af183c
Compare
f7f9d4a
to
37729be
Compare
β¦y for subfigures.
37729be
to
0430835
Compare
The before and after images look exactly the same? |
QuLogic
approved these changes
Aug 5, 2021
@jklymak Is the following (approximately, untested) close to what we need (as discussed in the call?) diff --git i/lib/matplotlib/figure.py w/lib/matplotlib/figure.py
index 4041793412..ef265b18cc 100644
--- i/lib/matplotlib/figure.py
+++ w/lib/matplotlib/figure.py
@@ -2001,6 +2001,14 @@ class SubFigure(FigureBase):
if parent._layoutgrid is not None:
self.init_layoutgrid()
+ @property
+ def dpi(self):
+ return self._parent.dpi
+
+ @dpi.setter
+ def dpi(self, value):
+ self._parent.dpi = value
+
def _redo_transform_rel_fig(self, bbox=None):
"""
Make the transSubfigure bbox relative to Figure transform. |
Related to your question on the call, copying the test and saving at different DPI: import matplotlib.pyplot as plt
# markers in the left- and right-most subplots should be the same
fig = plt.figure()
gs = fig.add_gridspec(1, 2)
ax0 = fig.add_subplot(gs[1])
ax0.scatter([1, 2, 3], [1, 2, 3], s=30, marker='s')
ax0.scatter([3, 4, 5], [1, 2, 3], s=[20, 30, 40], marker='s')
sfig = fig.add_subfigure(gs[0])
axs = sfig.subplots(1, 2)
for ax in [ax0, axs[0]]:
ax.scatter([1, 2, 3], [1, 2, 3], s=30, marker='s', color='r')
ax.scatter([3, 4, 5], [1, 2, 3], s=[20, 30, 40], marker='s', color='g')
fig.savefig('foo0.png', dpi=100)
fig.savefig('foo1.png', dpi=200)
fig.savefig('foo2.png', dpi=300) produces an image with changing scatter size (before this PR). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Summary
The dpi transform was not correct for scatter in subfigures. Notice how the marker sizes are too small in the left-most axes below.
Unfortunately the transform stack in collections is weird, in that the "transform" is just a Nx3x3 matrix rather than a full-fledged transform, so fixing directly is difficult. Instead we just figure out what the proper scaling is by transforming one inch.
NOTE I am deprecating the dpi argument to
collections.set_sizes
. I'm not clear why you would ever want to hard code this...Before
After
PR Checklist
pytest
passes).flake8
on changed files to check).flake8-docstrings
and runflake8 --docstring-convention=all
).doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).