Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

DOC: use OO-ish interface in image, contour, field examples#10865

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
jklymak merged 1 commit intomatplotlib:masterfromphobson:ooify-more-examples
Mar 27, 2018

Conversation

phobson
Copy link
Member

@phobsonphobson commentedMar 22, 2018
edited
Loading

PR Summary

Basic clean up ofpyplot ambiguity in some rather complex examples.

PR Checklist

  • Code is PEP 8 compliant
  • Documentation is sphinx and numpydoc compliant

@phobsonphobson changed the title(WIP) DOC: use OO-ish interface in image, contour, field examplesDOC: use OO-ish interface in image, contour, field examplesMar 23, 2018
Copy link
Member

@jklymakjklymak left a comment

Choose a reason for hiding this comment

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

I think this is great. A couple of minor quibbles that are totally take-it-or-leave-it. I'venot gone through and actually checked that all the examples still render OK. Presumably you've done that...

@@ -34,13 +34,11 @@
norm = cm.colors.Normalize(vmax=abs(Z).max(), vmin=-abs(Z).max())
cmap = cm.PRGn

fig= plt.figure()
fig, ((ax1, ax2), (ax3, ax4))= plt.subplots(nrows=2, ncols=2)
Copy link
Member

Choose a reason for hiding this comment

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

I'm not a huge fan of this syntax, versus justfig, axs = and then settingax = axs[row, col]. But not a show-stopper at all.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I'm with you on that. We do it both ways. And while I think consistency is good, maybe showing options are important too

jklymak reacted with thumbs up emoji
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not huge fan of putting arrays in variable names (ax1, ax2, ax3, ax4) rather than just the type (ax[0]). The former is so much harder to change later on, so I'm not sure we should actually be promoting it. If the row/column nature is a problem, you can always doax = ax.flatten(). My $0.02.

phobson reacted with thumbs up emoji

# Basic contour plot
CS =plt.contour(X, Y, Z)
CS1 =ax1.contour(X, Y, Z)
Copy link
Member

Choose a reason for hiding this comment

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

Why not reuseCS?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

My thought (which is behind e.g.,fig1, ax1 as well) is that I want it to be completely clear to a totally "n00b" (to programming, python, or matplotlib) that we're starting over and working on something new.

@@ -34,6 +34,6 @@

for ax, interp_method in zip(axes.flat, methods):
ax.imshow(grid, interpolation=interp_method, cmap='viridis')
ax.set_title(interp_method)
ax.set_title(str(interp_method))
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you need thestr here. set_title does that as well...

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

When I looked at the rendered page, theNone plot has no title, but in the current docs, is does have a title that says "None"

Copy link
Member

Choose a reason for hiding this comment

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

Oh, yes, I guessNone might have a different meaning. Fair enough

@@ -29,33 +29,31 @@
interp_cubic_min_E = mtri.CubicTriInterpolator(triang, z, kind='min_E')
zi_cubic_min_E = interp_cubic_min_E(xi, yi)

# Set up the figure
fig, axes = plt.subplots(nrows=2, ncols=2)
Copy link
Member

Choose a reason for hiding this comment

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

Not a fan ofaxes becuase of the plural/singular ambiguity....

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

fair point

Copy link
Member

Choose a reason for hiding this comment

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

super minor - I'd only change if someone else has serious issues...

@@ -22,24 +22,21 @@
data = np.array(data, dtype=[('x', np.float32), ('y', np.float32),
('u', np.float32), ('v', np.float32)])

fig, axes1 = plt.subplots(nrows=2, ncols=2)
Copy link
Member

Choose a reason for hiding this comment

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

Sincefig, doesn't have a number,axes1 shouldn't either.

I propose to decide on one canonical way of writing the second argument:axs vs.axes. Both seem to be used. I slightly tend toaxs in the sense of multipleax. Since Axes and Axis are both class namesaxes may just too easily be misinterpreted as multipleAxis or a singleAxes instance.

So proposed value here isaxs.

plt.subplot(212, sharex=ax1)
Pxx, freqs, bins, im = plt.specgram(x, NFFT=NFFT, Fs=Fs, noverlap=900)
fig, (ax1, ax2) = plt.subplots(nrows=2)
line, = ax1.plot(t, x)
Copy link
Member

Choose a reason for hiding this comment

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

line is not used afterwards, so it should be left out. Same with the return values on the following line.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I'm going to push back on this a bit. My gut feeling is that users -- especially new users -- are more likely to read these example than the docstrings.

So I think we should use this examples to be as explicit as possible about what each method is doing.

There are a lot of questions on SO along the lines of "how do I get an artist that's on my plot". While, there's a decent way to do that after the fact, I think it'd be nice to get users in the habbit of capturing things sooner rather than searching for them later.

Copy link
Member

Choose a reason for hiding this comment

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

I'm 100% with you that users are learning from the examples. Therefore a big 👍 for updating the examples.

My conclusion from learning by example is that the examples should be similar to real-world uses. I fear that if all the examples hadline = ax.plot(x, y), you'll find a lot of people having exactly that in their scripts, even if they don't useline at all - at least that's my experience with less-experienced users.

I'm fine, if you want to keep the return values onspecgram(). That's what the example is about. If so, it would be good to move the related comment from a few lines above directly to the function call. Something like:

Pxx, freqs, bins, im = ax2.specgram(x, NFFT=NFFT, Fs=Fs, noverlap=900)# returned values:# - Pxx: the periodograms# - freqs: the frequency vector# - bins: the centers of the time bins# - im: the matplotlib.image.AxesImage instance representing the data in the plot

However, since this is not aboutplot(), I wouldn't add the unusedline.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Well said. I'm on aboard.

fig, (ax1, ax2) = plt.subplots(nrows=2)
ax1.plot(t, x)
Pxx, freqs, bins, im = ax2.specgram(x, NFFT=NFFT, Fs=Fs, noverlap=900)
# The `specgram` method returns 4 objects. They are:
Copy link
Member

Choose a reason for hiding this comment

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

Unfortunately sphinx references don't work in code comments. See theresulting file.

I'll leave it up to you, if you want to keep it anyway.

@phobson
Copy link
MemberAuthor

phobson commentedMar 26, 2018 via email

Oh yeah. I wasn't trying to sphinx format. that was just habit.
On Mon, Mar 26, 2018 at 4:45 PM, Tim Hoffmann ***@***.***> wrote: ***@***.**** approved this pull request. ------------------------------ In examples/images_contours_and_fields/specgram_demo.py <#10865 (comment)> : > Fs = int(1.0 / dt) # the sampling frequency -# Pxx is the segments x freqs array of instantaneous power, freqs is -# the frequency vector, bins are the centers of the time bins in which -# the power is computed, and im is the matplotlib.image.AxesImage -# instance - -ax1 = plt.subplot(211) -plt.plot(t, x) -plt.subplot(212, sharex=ax1) -Pxx, freqs, bins, im = plt.specgram(x, NFFT=NFFT, Fs=Fs, noverlap=900) +fig, (ax1, ax2) = plt.subplots(nrows=2) +ax1.plot(t, x) +Pxx, freqs, bins, im = ax2.specgram(x, NFFT=NFFT, Fs=Fs, noverlap=900) +# The `specgram` method returns 4 objects. They are: Unfortunately sphinx references don't work in code comments. See the resulting file <https://8320-1385122-gh.circle-artifacts.com/0/home/circleci/project/doc/build/html/gallery/images_contours_and_fields/specgram_demo.html#sphx-glr-gallery-images-contours-and-fields-specgram-demo-py> . I'll leave it up to you, if you want to keep it anyway. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <#10865 (review)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ABHCoxDqM-kOFA2t9Fo6qxdcuguUK0SIks5tiX2fgaJpZM4S3s7h> .

@jklymakjklymak merged commitad3a303 intomatplotlib:masterMar 27, 2018
@phobsonphobson deleted the ooify-more-examples branchApril 30, 2018 21:25
@tacaswelltacaswell added this to thev3.0 milestoneJun 28, 2018
tacaswell pushed a commit to tacaswell/matplotlib that referenced this pull requestJun 28, 2018
DOC: use OO-ish interface in image, contour, field examplesThis removes change to lib/matplotlib/axes/_base.py inPRmatplotlib#10865 and commitad3a303
tacaswell pushed a commit to tacaswell/matplotlib that referenced this pull requestJun 28, 2018
DOC: use OO-ish interface in image, contour, field examplesThis removes change to lib/matplotlib/axes/_base.py inPRmatplotlib#10865 and commitad3a303
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@dopplershiftdopplershiftdopplershift left review comments

@jklymakjklymakjklymak approved these changes

@timhoffmtimhoffmtimhoffm approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
v3.0.0
Development

Successfully merging this pull request may close these issues.

5 participants
@phobson@dopplershift@jklymak@timhoffm@tacaswell

[8]ページ先頭

©2009-2025 Movatter.jp