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

Conversation

ehallam
Copy link
Contributor

@ehallam ehallam commented Mar 4, 2022

Added plt.show() at the end of each necessary block.
Moved and reworded title section.

@ehallam ehallam force-pushed the 45772-add-plot-show branch 3 times, most recently from 16cbbaa to 77e6e25 Compare March 5, 2022 17:00
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you changing to use plt.show() and not just adding ; which render the plots?


@savefig 04_airqual_quick.png
air_quality.plot()
In [1]: air_quality.plot()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

umm you can just add a ; no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jreback. Thanks for your comment. I understand that adding the semicolon at the end of air_quality.plot() line will suppress the Out[N]: AxesSubplot:xlabel='datetime' line from the output, but that's not how I understood the purpose of issue #45772.

I believe that the fix for the issue needs to explicitly show the plt.show(), not because it is necessary in that particular example, but so that the user understands plt.show() is the function that can be called to render the plot, rather than it just automagically appearing below the cell. Without this, a new user may believe that the call to plot() is actually rendering the figure. In the scenario below, for example, we need to explicitly call plt.show() to render the charts at the right point in the code. I think the hope is that including plt.show() in the example will provide them with the knowledge to be able to do this.

for station in air_quality.columns:
    print(station)

    fig = air_quality[station].plot(figsize=(12, 4))
    fig.set_ylabel("NO$_2$ concentration")
    plt.show()

    fig = air_quality[station].plot.area(figsize=(12, 4))
    fig.set_ylabel("NO$_2$ concentration")
    plt.show()

@jreback jreback added the Visualization plotting label Mar 5, 2022
@ehallam ehallam force-pushed the 45772-add-plot-show branch 4 times, most recently from bd9ba34 to cb3fe2d Compare April 10, 2022 13:34
@ehallam
Copy link
Contributor Author

ehallam commented Apr 10, 2022

Screenshot 2022-04-10 at 12-17-43 How do I create plots in pandas — pandas 1 5 0 dev0 661 g0442a4cb65 dirty documentation

@ehallam ehallam force-pushed the 45772-add-plot-show branch from 92c3cb2 to cb426b5 Compare April 10, 2022 14:25
@ehallam ehallam marked this pull request as ready for review April 10, 2022 16:33

@savefig 04_airqual_scatter.png
air_quality.plot.scatter(x="station_london", y="station_paris", alpha=0.5)

In [1]: air_quality.plot.scatter(x="station_london", y="station_paris", alpha=0.5)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you not letting these run with python mode. this is not what we do elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jreback, if I run them in Python mode it displays as below with the extra Out[4] line, which is why I didn't run them in Python mode. I just thought it looked cleaner that way as the Out line doesn't add value.

Screenshot 2022-04-10 at 19-09-27 How do I create plots in pandas — pandas 1 5 0 dev0 667 gcb426b57ae dirty documentation

If we wanted to get rid of this out line while still running in Python mode I can add semi colons to the end of each .plot() line as demonstrated below. Which of these would you prefer me to do?

Screenshot 2022-04-10 at 19-12-08 How do I create plots in pandas — pandas 1 5 0 dev0 667 gcb426b57ae dirty documentation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just assign it instead. this is a bit non-standard what you are doing and that's not great.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jreback how does this look? Many thanks for your help

Screenshot 2022-04-11 at 09-29-31 How do I create plots in pandas — pandas 1 5 0 dev0 667 gcb426b57ae dirty documentation

@jreback jreback added this to the 1.5 milestone Apr 10, 2022
@ehallam ehallam force-pushed the 45772-add-plot-show branch from 77bc42b to 2dc4968 Compare April 13, 2022 07:59
@ehallam ehallam force-pushed the 45772-add-plot-show branch from 2dc4968 to 4cdb735 Compare April 13, 2022 08:03
@ehallam ehallam requested a review from jreback April 20, 2022 09:55
Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, this change looks okay. LGTM

@jreback jreback merged commit 8980af7 into pandas-dev:main Apr 26, 2022
@jreback
Copy link
Contributor

jreback commented Apr 26, 2022

thanks @ehallam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DOC: Addition of plt.show() in the "How to create plots in pandas?" section of the Getting started tutorials
3 participants