DOC: clearing out some instances of using pylab in the docs #6957

Merged
merged 1 commit into from Sep 1, 2016

Conversation

Projects
None yet
6 participants
Member

phobson commented Aug 18, 2016

Note: there are some instances where I from matplotlib import pyplot, since that's what I'm in the habit of doing now.

Obviously I prefer it that way, but if I need to switch from import matplotlib.pyplot as plt, just let me know. I understand the inertial forces at work there.

mdboom added the needs_review label Aug 18, 2016

Member

story645 commented Aug 19, 2016

I'd vote for import matplotlib.pyplot as plt only 'cause I've seen those little inconsistencies trip people up badly.

Member

phobson commented Aug 19, 2016

good point @story645

non-beginners will already have an opinion about aliases and will be able to read/modify as they see fit.

@QuLogic QuLogic commented on an outdated diff Aug 19, 2016

doc/pyplots/boxplot_demo.py
@@ -4,62 +4,68 @@
# Example boxplot code
#
-from pylab import *
+import numpy
@QuLogic

QuLogic Aug 19, 2016

Member

import numpy as np is the usual thing.

@QuLogic QuLogic and 1 other commented on an outdated diff Aug 19, 2016

doc/pyplots/boxplot_demo.py
-# basic plot
@QuLogic

QuLogic Aug 19, 2016 edited

Member

Are these comments wrong? Why remove them?

@phobson

phobson Aug 19, 2016

Member

I added them to the figures as titles -- figure that just as informative when reading the code.

@QuLogic QuLogic commented on an outdated diff Aug 19, 2016

doc/pyplots/boxplot_demo.py
-# fake up some more data
-spread= rand(50) * 100
-center = ones(25) * 40
-flier_high = rand(10) * 100 + 100
-flier_low = rand(10) * -100
-d2 = concatenate( (spread, center, flier_high, flier_low), 0 )
+# fake up some more data'
@QuLogic

QuLogic Aug 19, 2016

Member

Accidental change.

@QuLogic QuLogic commented on an outdated diff Aug 19, 2016

doc/pyplots/whats_new_98_4_fill_between.py
import numpy as np
x = np.arange(0.0, 2, 0.01)
y1 = np.sin(2*np.pi*x)
y2 = 1.2*np.sin(4*np.pi*x)
-fig = figure()
+fig, ax = plt.subplots()
ax = fig.add_subplot(111)
@QuLogic

QuLogic Aug 19, 2016

Member

You've got an extra Axes here.

@QuLogic QuLogic commented on an outdated diff Aug 19, 2016

examples/api/colorbar_only.py
@@ -71,4 +71,4 @@
orientation='horizontal')
cb3.set_label('Custom extension lengths, some other units')
-pyplot.show()
+fig.show()
@QuLogic

QuLogic Aug 19, 2016

Member

plt.show?

@story645 story645 and 1 other commented on an outdated diff Aug 19, 2016

doc/faq/installing_faq.rst
@@ -23,9 +23,9 @@ complexities. Open up a UNIX shell or a DOS command prompt and cd into a
directory containing a minimal example in a file. Something like
:file:`simple_plot.py` for example::
- from pylab import *
- plot([1,2,3])
- show()
+ import matplotlib.pyplot as plt
+ plt.plot([1,2,3])
@story645

story645 Aug 19, 2016

Member

any good reason to not do:

fig, ax = plt.subplots()
ax.plot([1,2,3])
fig.show()

since it's only one more line?

@phobson

phobson Aug 19, 2016

Member

I prefer using subplots too, but I figured the intro was intended to be hyper-brief.

@story645

story645 Aug 19, 2016

Member

Meh, I feel like one more line + good practice is still hyper brief. shrugs

@phobson

phobson Aug 19, 2016

Member

I think you're right. I'll change it.

@story645 story645 commented on an outdated diff Aug 19, 2016

doc/pyplots/whats_new_99_mplot3d.py
-fig = pylab.figure()
+fig = plt.figure()
ax = Axes3D(fig)
X = np.arange(-5, 5, 0.25)
@story645

story645 Aug 19, 2016

Member

Maybe move data pieces above plotting code?

@story645 story645 commented on the diff Aug 19, 2016

examples/units/units_scatter.py
ax3.scatter(xsecs, xsecs, yunits=hertz)
ax3.yaxis.set_units(minutes)
ax3.axis([0, 10, 0, 1])
-show()
+fig.tight_layout()
+plt.show()
@story645

story645 Aug 19, 2016

Member

consistency of fig.show() or plt.show()? (my preference is for fig.show()...)

@phobson

phobson Aug 19, 2016

Member

mine too, but some examples have more than 1 figure, so pyplot.show() shows them all.

Happy to change this one though.

@phobson

phobson Aug 19, 2016

Member

also, an advantage of pyplot.show() is that it pulls up a blocking interactive window when fig.show() won't.

IOW, if I run python doc/path/to/some/example.py and it has fig.show(), the figure closes before I can look it. With pyplot.show(), it stays open until I close it.

@story645

story645 Aug 19, 2016

Member

Hmm, the new I guess use plt.show() for all?

@tacaswell

tacaswell Aug 20, 2016

Owner

I would lean towards plt.show() over fig.show()

@phobson phobson added a commit to phobson/matplotlib that referenced this pull request Aug 19, 2016

@phobson phobson DOC: alias numpy and address other comments in #6957 d540abf

QuLogic was assigned by tacaswell Aug 20, 2016

@dopplershift dopplershift commented on an outdated diff Aug 22, 2016

doc/faq/installing_faq.rst
@@ -23,9 +23,10 @@ complexities. Open up a UNIX shell or a DOS command prompt and cd into a
directory containing a minimal example in a file. Something like
:file:`simple_plot.py` for example::
- from pylab import *
- plot([1,2,3])
- show()
+ import matplotlib.pyplot as plt
+ fig, ax = plt.subplots()
+ ax.plot([1,2,3])
+ fig.show()
@dopplershift

dopplershift Aug 22, 2016

Contributor

plt.show() ?

@dopplershift dopplershift commented on an outdated diff Aug 22, 2016

doc/pyplots/boxplot_demo.py
-# basic plot
-boxplot(data)
-#savefig('box1')
+fig1, ax1 = plt.subplots()
+ax1.set_title('basic plot')
@dopplershift

dopplershift Aug 22, 2016 edited

Contributor

Should the title(s) be capitalized?

Member

QuLogic commented Aug 30, 2016

Ping?

Member

phobson commented Aug 31, 2016

@QuLogic took care of those last comments.

let me know if you want me to squash/fixup the everything to a single commit. I'm comfortable with and happy to do that.
-p

Member

QuLogic commented Aug 31, 2016

Sure, go ahead.

@phobson phobson DOC: move a few examples away from pylab
3e25df7

@QuLogic QuLogic merged commit 32eb2c5 into matplotlib:master Sep 1, 2016

2 of 3 checks passed

continuous-integration/travis-ci/pr The Travis CI build failed
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
coverage/coveralls Coverage increased (+0.002%) to 70.619%
Details

QuLogic removed the needs_review label Sep 1, 2016

@QuLogic QuLogic added a commit to QuLogic/matplotlib that referenced this pull request Sep 1, 2016

@QuLogic QuLogic Merge pull request #6957 from phobson/partial-update-pylab-examples
DOC: clearing out some instances of using pylab in the docs
d5af573
Member

QuLogic commented Sep 1, 2016

Backported to v2.x as d5af573.

phobson deleted the phobson:partial-update-pylab-examples branch Sep 2, 2016

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