diff --git a/doc/source/getting_started/intro_tutorials/04_plotting.rst b/doc/source/getting_started/intro_tutorials/04_plotting.rst
index 1e0505a2f0e87..b6f1ac212f821 100644
--- a/doc/source/getting_started/intro_tutorials/04_plotting.rst
+++ b/doc/source/getting_started/intro_tutorials/04_plotting.rst
@@ -2,6 +2,12 @@
{{ header }}
+How do I create plots in pandas?
+----------------------------------
+
+.. image:: ../../_static/schemas/04_plot_overview.svg
+ :align: center
+
.. ipython:: python
import pandas as pd
@@ -35,12 +41,6 @@
-How to create plots in pandas?
-------------------------------
-
-.. image:: ../../_static/schemas/04_plot_overview.svg
- :align: center
-
.. raw:: html
@@ -52,6 +52,7 @@ I want a quick visual check of the data.
@savefig 04_airqual_quick.png
air_quality.plot()
+ plt.show()
With a ``DataFrame``, pandas creates by default one line plot for each of
the columns with numeric data.
@@ -68,10 +69,19 @@ the columns with numeric data.
I want to plot only the columns of the data table with the data from Paris.
+.. ipython:: python
+ :suppress:
+
+ # We need to clear the figure here as, within doc generation, the plot
+ # accumulates data on each plot(). This is not needed when running
+ # in a notebook, so is suppressed from output.
+ plt.clf()
+
.. ipython:: python
@savefig 04_airqual_paris.png
air_quality["station_paris"].plot()
+ plt.show()
To plot a specific column, use the selection method of the
: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
@savefig 04_airqual_scatter.png
air_quality.plot.scatter(x="station_london", y="station_paris", alpha=0.5)
+ plt.show()
.. raw:: html
@@ -125,6 +136,7 @@ method is applicable on the air quality example data:
@savefig 04_airqual_boxplot.png
air_quality.plot.box()
+ plt.show()
.. raw:: html
@@ -148,6 +160,7 @@ I want each of the columns in a separate subplot.
@savefig 04_airqual_area_subplot.png
axs = air_quality.plot.area(figsize=(12, 4), subplots=True)
+ plt.show()
Separate subplots for each of the data columns are supported by the ``subplots`` argument
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.
fig, axs = plt.subplots(figsize=(12, 4))
air_quality.plot.area(ax=axs)
- @savefig 04_airqual_customized.png
axs.set_ylabel("NO$_2$ concentration")
+ @savefig 04_airqual_customized.png
fig.savefig("no2_concentrations.png")
+ plt.show()
.. ipython:: python
:suppress:
@@ -208,6 +222,7 @@ This strategy is applied in the previous example:
air_quality.plot.area(ax=axs) # Use pandas to put the area plot on the prepared Figure/Axes
axs.set_ylabel("NO$_2$ concentration") # Do any Matplotlib customization you like
fig.savefig("no2_concentrations.png") # Save the Figure/Axes using the existing Matplotlib method.
+ plt.show() # Display the plot
.. raw:: html