-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
DOC: add to transforms tutorial re fig.dpi_scale_trans #11215
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
Conversation
fae876c
to
4d1ca36
Compare
c19783e
to
9f0e5a7
Compare
ax.transData.transform((xdata[0], ydata[0]))) | ||
# plot a circle around the point that is 50 points in diameter... | ||
circle = mpatches.Circle((x, y), 50/72, fill=None, | ||
transform=fig.dpi_scale_trans) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is a good example. If you want a circle with 50 point radius you'd just plot a plot
with circular marker
ax.plot(xdata, ydata, ls="", marker="o", ms=100, mec="k", mfc="none")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure fair enough. The point wasn't to do that particular thing, but just to show the use of inverted, which the tutorial barely touched on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be good to explain inverted()
somewhere.
In the example here inverted()
is not well explained. It's just there. Second, the example reads like this would be the way to go for placing some artist at a point in data coordinates. I doubt that is how one should do it. Essentially because of the drawback that it does not shift together with the data points.
To place some general path, like the ellipse here one could use
ell = mpatches.Ellipse((0, 0), 150/72., 130/72., angle=40)
p = ell.get_path()
verts = ell.get_patch_transform().transform(p.vertices)
codes = p.codes
p = mpath.Path(verts, codes)
ax.scatter(xdata, ydata, marker=p, s = (2*72)**2)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough - inverted was explained below, but probably needs to be explained here.
Your suggested change is ... inelegant.... There must be a better way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh:
mytrans = fig.dpi_scale_trans + mtransforms.ScaledTranslation(xdata[0], ydata[0], ax.transData)
print(mytrans)
ell = mpatches.Ellipse((0, 0), 150/72., 130/72., angle=40, transform=mytrans)
ax.add_patch(ell)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a very good example. The problem is that ScaledTranslation
and transform chaining are discussed later. So one should point/link to that in the text or maybe put the whole section more downwards?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I modified the description below this to account for the changes here...
9f0e5a7
to
23797b9
Compare
Not sure about the small figures in the one block; they are fine on my screen but maybe too small on some? |
circ = mpatches.Circle((2.5, 2), 1.0, transform=fig.dpi_scale_trans, | ||
facecolor='yellow', alpha=0.5) | ||
ax.add_patch(circ) | ||
plt.show() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could it make sense to get rid of that strong green and pale yellow? After all it's the circle that is important here, not the 1000 scatter points.
744edfa
to
3b093dc
Compare
3b093dc
to
e24619d
Compare
No thats too small. Changed it... |
e24619d
to
3127333
Compare
# first be transfromed to ``display`` coordinates (``[ 358.4 475.2]`` on | ||
# a 200-dpi monitor) and then those coordinates | ||
# would be scaled by ``fig.dpi_scale_trans`` pushing the center of | ||
# the ellipse well off the screen (i.e. ``[ 71680. 95040.]``). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mhh, why do you explain all the things that would go wrong if you did something other than you're actually doing? Instead why not simply explain what you are doing and giving the coordinates for the actual case?
I would also think this is better done after the example code.
3127333
to
22a3703
Compare
It would still be good to have an |
for artists placed in an axes or figure to have their transform set to | ||
something *other* than the ``IdentityTransform()``; the default when an artist | ||
is placed on an axes using ``~Axes.axes.add_artist`` is for the transform to be | ||
`ax.transData`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some mixup between single and double quotes here?
-
`~.transforms.IdentityTransform()`
-
`~.Axes.axes.add_artist`
-
``ax.transData``
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should mostly be single '`' I think (so they link).
plt.show() | ||
|
||
############################################################################### | ||
# If we change the figure size... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like ellipses (...). Either one states what this is meant to be left out or not. In this case, it's probably useful to descibe what happens if you change the figure size, e.g.
"If you change the figure size, the circle does not change its absolute position is hence cropped."
or similar.
There is already some example for Thinking about it for some time I do not have a good idea for another Examples where I used
They all seem to be too complex for a simple example in a tutorial. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modulo the double backticks in the second paragraph, I would approve this. This is a significant improvement compared to the previous version of the tutorial and adds a really useful example for using inches as figure coordinates.
I would not postpone this just because no other inverted
example can be found. In the limit this can be another PR if it's really desired.
This got a lot of commentary, I think it can be merged.... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall great.
Some minor style issuse: The ones mentioned and additionally:
- Some indents for line continuations are weird
- Could use
fig, ax = plt.subplots
throughout.
lib/matplotlib/axes/_base.py
Outdated
@@ -1811,6 +1811,10 @@ def add_artist(self, a): | |||
to manually update the dataLim if the artist is to be included in | |||
autoscaling. | |||
|
|||
If no ``transform`` has been specified when creating the artist (e.g. | |||
``artist.get_transform()==None``) then the transform is set to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spaces around ==
ax.set_xlim((0, 1)) | ||
|
||
trans = fig.dpi_scale_trans + \ | ||
transforms.ScaledTranslation(xdata[0], ydata[0], ax.transData) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strange indent/spacing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, hmmm. I double indent for line continuations. Is that strange? I thought it helped make it clear that its not a new code block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use ()
continuation instead of \
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK< change indent too.
|
||
# plot an ellipse around the point that is 150 x 130 points in diameter... | ||
circle = mpatches.Ellipse((0, 0), 150/72, 130/72, angle=40, fill=None, | ||
transform=trans) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strange indent/spacing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... as above...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These typically get moved up to align with the opening (
that it is in.
# and then translate the data to `xdata[0]` and `ydata[0]` in data space. | ||
# | ||
# In interactive use, the ellipse stays the same size even if the | ||
# axes limits are changed via zoom, but the ellipse's size doesn't change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Repetitive sentence.
22a3703
to
0059f22
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please tell me if I get too picky about the formatting. These things just jump to my eye. So I mention them. They are not essential for a merge if it gets too much.
ax.plot(xdata, ydata, "o") | ||
ax.set_xlim((0, 1)) | ||
|
||
trans = (fig.dpi_scale_trans + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra space before =
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...we love you because these things jump out at you...
circ = patches.Circle((0.5, 0.5), 0.25, transform=ax.transAxes, | ||
facecolor='yellow', alpha=0.5) | ||
circ = mpatches.Circle((0.5, 0.5), 0.25, transform=ax.transAxes, | ||
facecolor='blue', alpha=0.75) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the continued line should start after the enclosing bracket:
circ = mpatches.Circle((0.5, 0.5), 0.25, transform=ax.transAxes,
facecolor='blue', alpha=0.75)
This happens multiple times in the example (not only your edits).
0059f22
to
35e3055
Compare
+-----------+-----------------------------+-----------------------------------+ | ||
+----------------+-----------------------------+-----------------------------------+ | ||
|Coordinates |Transformation object |Description | | ||
+----------------+-----------------------------+-----------------------------------+ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hint: You can make the texts above headers by changing all -
to =
in this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few typos noticed during a quick reading of the text.
plt.show() | ||
|
||
############################################################################### | ||
# If we change the figure size the circle does not change its absolute |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
" (...) the circle does not change its absolute position is cropped." Would it not be missing some punctuation at the end of the sentence? Not sure that I understand what is cropped.
plt.show() | ||
|
||
############################################################################### | ||
# Another use is putting a patch with a set physical dimmension around a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dimension
# | ||
# Note the use of the plus operator on the transforms below. | ||
# This code says: first apply the scale transformation ``fig.dpi_scale_trans`` | ||
# to make the Ellipse the proper size, but still centered at (0, 0), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the capital E in "Ellipse" used on purpose?
# in data space to the correct spot. | ||
# If we had done the ``ScaledTranslation`` first, then | ||
# ``xdata[0]`` and ``ydata[0]`` would | ||
# first be transfromed to ``display`` coordinates (``[ 358.4 475.2]`` on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
transformed
35e3055
to
b81ca50
Compare
@afvincent thanks for ctaching the typos... Someone want to merge this? |
There seem to be a conflict, please backport manually |
PR Summary
The transforms tutorial mentions
fig.dpi_scale_trans
but it really seems it should be up in the list of basic transforms. Added a couple of examples as well...PR Checklist