Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 1 commit into from
Jun 5, 2018

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented May 10, 2018

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

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@jklymak jklymak changed the title DOC: add infor to transforms tutorial about fig.dpi_scale_trans DOC: add to transforms tutorial re fig.dpi_scale_trans May 10, 2018
@jklymak jklymak closed this May 10, 2018
@jklymak jklymak force-pushed the doc-transform-tut-dpi branch from fae876c to 4d1ca36 Compare May 10, 2018 04:40
@jklymak jklymak reopened this May 10, 2018
@jklymak jklymak force-pushed the doc-transform-tut-dpi branch 2 times, most recently from c19783e to 9f0e5a7 Compare May 10, 2018 17:14
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)

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")

Copy link
Member Author

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.

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) 

Copy link
Member Author

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?

Copy link
Member Author

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)

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?

Copy link
Member Author

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...

@jklymak
Copy link
Member Author

jklymak commented May 10, 2018

https://9697-1385122-gh.circle-artifacts.com/0/home/circleci/project/doc/build/html/tutorials/advanced/transforms_tutorial.html#sphx-glr-tutorials-advanced-transforms-tutorial-py

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()

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.

@jklymak jklymak force-pushed the doc-transform-tut-dpi branch 2 times, most recently from 744edfa to 3b093dc Compare May 10, 2018 20:05
@ImportanceOfBeingErnest
Copy link
Member

To give you an idea of how the small figures look on my screen:

image

It's probably a matter of taste.

@jklymak jklymak force-pushed the doc-transform-tut-dpi branch from 3b093dc to e24619d Compare May 10, 2018 20:12
@jklymak
Copy link
Member Author

jklymak commented May 10, 2018

No thats too small. Changed it...

@jklymak jklymak force-pushed the doc-transform-tut-dpi branch from e24619d to 3127333 Compare May 10, 2018 20:48
# 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.]``).

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.

@jklymak jklymak force-pushed the doc-transform-tut-dpi branch from 3127333 to 22a3703 Compare May 10, 2018 21:35
@jklymak
Copy link
Member Author

jklymak commented May 10, 2018

It would still be good to have an inverted example in here somewhere that was useful. Suggestions?

@jklymak jklymak added this to the v2.2-doc milestone May 14, 2018
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`.

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``

Copy link
Member

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...

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.

@ImportanceOfBeingErnest
Copy link
Member

There is already some example for inverted using simple coordinates towards the top of the page.

Thinking about it for some time I do not have a good idea for another inverted example. The problem with inverted is that it freezes the transform. So in most cases you try to avoid using it. And in cases you need to use it, it gets a little complicated because you would need to add a callback to garantee interactivity.

Examples where I used inverted on Stackoverflow:

They all seem to be too complex for a simple example in a tutorial.

Copy link
Member

@ImportanceOfBeingErnest ImportanceOfBeingErnest left a 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.

@jklymak
Copy link
Member Author

jklymak commented May 28, 2018

This got a lot of commentary, I think it can be merged....

Copy link
Member

@timhoffm timhoffm left a 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:

  1. Some indents for line continuations are weird
  2. Could use fig, ax = plt.subplots throughout.

@@ -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
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strange indent/spacing

Copy link
Member Author

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.

Copy link
Member

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 \?

Copy link
Member Author

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strange indent/spacing

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... as above...

Copy link
Member

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repetitive sentence.

@jklymak jklymak force-pushed the doc-transform-tut-dpi branch from 22a3703 to 0059f22 Compare May 29, 2018 04:27
Copy link
Member

@timhoffm timhoffm left a 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 +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra space before =

Copy link
Member Author

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)
Copy link
Member

@timhoffm timhoffm May 29, 2018

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).

@jklymak jklymak force-pushed the doc-transform-tut-dpi branch from 0059f22 to 35e3055 Compare May 29, 2018 13:51
+-----------+-----------------------------+-----------------------------------+
+----------------+-----------------------------+-----------------------------------+
|Coordinates |Transformation object |Description |
+----------------+-----------------------------+-----------------------------------+
Copy link
Member

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.

Copy link
Contributor

@afvincent afvincent left a 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
Copy link
Contributor

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
Copy link
Contributor

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),
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transformed

@jklymak jklymak force-pushed the doc-transform-tut-dpi branch from 35e3055 to b81ca50 Compare May 30, 2018 00:36
@jklymak
Copy link
Member Author

jklymak commented May 30, 2018

@afvincent thanks for ctaching the typos... Someone want to merge this?

@phobson phobson merged commit bc0882e into matplotlib:master Jun 5, 2018
@lumberbot-app
Copy link

lumberbot-app bot commented Jun 5, 2018

There seem to be a conflict, please backport manually

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants