-
-
Notifications
You must be signed in to change notification settings - Fork 8k
use plt.subplots() in examples as much as possible #1462
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
Changes from 1 commit
5c54d8f
e12a16e
9a31dbb
79df1b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
At the recent LBL Software Carpentry Workshop, it was pointed out that there's an inconsistency within our documentation for how to create new figures with subplots. Indeed, most examples were using the old way, something like: fig = plt.figure() ax = plt.subplot(111) # or plt.add_subplot(111) This patch changes a whole bunch of instances like the above to: fig, ax = plt.subplots() We should strive to have a minimal amount of constants in our code, especially unusual ones like `111`, which only make sense to Matlab refugees. I have left unchanged examples which were using axes keywords passed to subplot() and add_subplot(), since those end up transforming things like: figure() subplot(111, axisbg='w') to plt.subplots(subplot_kw=dict(axisbg='w')) which isn't necessarily better. I also did not touch most of the user_interfaces examples, since those did not involve using plt, but instead explicitly imported Figure, and used the OO approach on Figure instances. Also updated instaces where the old "import pylab as p" convention was used to use our standard "import matplotlib.pyplot as plt" I have also updated some, but not all uses of subplot(121) etc, but I'm a bit exhausted after doing all of these.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,10 @@ | |
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas | ||
from matplotlib.figure import Figure | ||
|
||
fig = Figure() | ||
canvas = FigureCanvas(fig) | ||
ax = fig.add_subplot(111) | ||
fig, ax = plt.subplots() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't agree with this one. (use of plt) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with @pelson. This example is for exposing the object-oriented interface. Using the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, i don't agree with this one either, and agree with both of you, change committed. |
||
ax.plot([1,2,3]) | ||
ax.set_title('hi mom') | ||
ax.grid(True) | ||
ax.set_xlabel('time') | ||
ax.set_ylabel('volts') | ||
canvas.print_figure('test') | ||
fig.canvas.print_figure('test') |
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'm not sure whether:
is better than
or even
ax = plt.axes()
Note:
I do agree that:
is better than
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 inspired me to make #1475 to have plt.subplot() work just like plt.axes().
I'm happy to change this to just be plt.axes()
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.
Cool. Glad it inspired you! 😄
I think we can use your new syntax here now. Thoughts?
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.
On Tue, Nov 13, 2012 at 1:37 AM, Phil Elson notifications@github.comwrote:
This is the sort of bifurcation that I was talking about in the recent
thread on mpl-devel - but no solution is perfect...