Skip to content

Commit 4cdb735

Browse files
committed
DOC: Added plt.show() at the end of each necessary block (pandas-dev#45772)
Reworded and moved title to the top of the page
1 parent f976aa6 commit 4cdb735

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

doc/source/getting_started/intro_tutorials/04_plotting.rst

+22-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
{{ header }}
44

5+
How do I create plots in pandas?
6+
----------------------------------
7+
8+
.. image:: ../../_static/schemas/04_plot_overview.svg
9+
:align: center
10+
511
.. ipython:: python
612
713
import pandas as pd
@@ -35,12 +41,6 @@
3541
</ul>
3642
</div>
3743

38-
How to create plots in pandas?
39-
------------------------------
40-
41-
.. image:: ../../_static/schemas/04_plot_overview.svg
42-
:align: center
43-
4444
.. raw:: html
4545

4646
<ul class="task-bullet">
@@ -52,6 +52,7 @@ I want a quick visual check of the data.
5252
5353
@savefig 04_airqual_quick.png
5454
air_quality.plot()
55+
plt.show()
5556
5657
With a ``DataFrame``, pandas creates by default one line plot for each of
5758
the columns with numeric data.
@@ -68,10 +69,19 @@ the columns with numeric data.
6869

6970
I want to plot only the columns of the data table with the data from Paris.
7071

72+
.. ipython:: python
73+
:suppress:
74+
75+
# We need to clear the figure here as, within doc generation, the plot
76+
# accumulates data on each plot(). This is not needed when running
77+
# in a notebook, so is suppressed from output.
78+
plt.clf()
79+
7180
.. ipython:: python
7281
7382
@savefig 04_airqual_paris.png
7483
air_quality["station_paris"].plot()
84+
plt.show()
7585
7686
To plot a specific column, use the selection method of the
7787
:ref:`subset data tutorial <10min_tut_03_subset>` in combination with the :meth:`~DataFrame.plot`
@@ -94,6 +104,7 @@ I want to visually compare the :math:`NO_2` values measured in London versus Par
94104
95105
@savefig 04_airqual_scatter.png
96106
air_quality.plot.scatter(x="station_london", y="station_paris", alpha=0.5)
107+
plt.show()
97108
98109
.. raw:: html
99110

@@ -125,6 +136,7 @@ method is applicable on the air quality example data:
125136
126137
@savefig 04_airqual_boxplot.png
127138
air_quality.plot.box()
139+
plt.show()
128140
129141
.. raw:: html
130142

@@ -148,6 +160,7 @@ I want each of the columns in a separate subplot.
148160
149161
@savefig 04_airqual_area_subplot.png
150162
axs = air_quality.plot.area(figsize=(12, 4), subplots=True)
163+
plt.show()
151164
152165
Separate subplots for each of the data columns are supported by the ``subplots`` argument
153166
of the ``plot`` functions. The builtin options available in each of the pandas plot
@@ -180,9 +193,10 @@ I want to further customize, extend or save the resulting plot.
180193
181194
fig, axs = plt.subplots(figsize=(12, 4))
182195
air_quality.plot.area(ax=axs)
183-
@savefig 04_airqual_customized.png
184196
axs.set_ylabel("NO$_2$ concentration")
197+
@savefig 04_airqual_customized.png
185198
fig.savefig("no2_concentrations.png")
199+
plt.show()
186200
187201
.. ipython:: python
188202
:suppress:
@@ -208,6 +222,7 @@ This strategy is applied in the previous example:
208222
air_quality.plot.area(ax=axs) # Use pandas to put the area plot on the prepared Figure/Axes
209223
axs.set_ylabel("NO$_2$ concentration") # Do any Matplotlib customization you like
210224
fig.savefig("no2_concentrations.png") # Save the Figure/Axes using the existing Matplotlib method.
225+
plt.show() # Display the plot
211226

212227
.. raw:: html
213228

0 commit comments

Comments
 (0)