Skip to content

DOC: Added plt.show() at the end of each necessary block #46231

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

Merged
merged 1 commit into from
Apr 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions doc/source/getting_started/intro_tutorials/04_plotting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -35,12 +41,6 @@
</ul>
</div>

How to create plots in pandas?
------------------------------

.. image:: ../../_static/schemas/04_plot_overview.svg
:align: center

.. raw:: html

<ul class="task-bullet">
Expand All @@ -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.
Expand All @@ -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`
Expand All @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand Down