DOC: add to transforms tutorial re fig.dpi_scale_trans - #11215
Conversation
fae876c to
4d1ca36
Compare
c19783e to
9f0e5a7
Compare
There was a problem hiding this comment.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Some mixup between single and double quotes here?
-
`~.transforms.IdentityTransform()`
-
`~.Axes.axes.add_artist`
-
``ax.transData``
There was a problem hiding this comment.
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.
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. |
ImportanceOfBeingErnest
left a comment
There was a problem hiding this comment.
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.... |
timhoffm
left a comment
There was a problem hiding this comment.
Overall great.
Some minor style issuse: The ones mentioned and additionally:
- Some indents for line continuations are weird
- Could use
fig, ax = plt.subplotsthroughout.
| autoscaling. | ||
|
|
||
| If no ``transform`` has been specified when creating the artist (e.g. | ||
| ``artist.get_transform()==None``) then the transform is set to |
| 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.
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.
Can you use () continuation instead of \?
|
|
||
| # 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.
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. |
22a3703 to
0059f22
Compare
timhoffm
left a comment
There was a problem hiding this comment.
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.
...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.
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.
Hint: You can make the texts above headers by changing all - to = in this line.
afvincent
left a comment
There was a problem hiding this comment.
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.
" (...) 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 |
| # | ||
| # 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.
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 |
35e3055 to
b81ca50
Compare
|
@afvincent thanks for ctaching the typos... Someone want to merge this? |


PR Summary
The transforms tutorial mentions
fig.dpi_scale_transbut it really seems it should be up in the list of basic transforms. Added a couple of examples as well...PR Checklist