Skip to content

QST: DataFrame.plot() vs Series.plot() have inconsistency wrt reuse plot #59716

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

Open
2 tasks done
pollo-coder opened this issue Sep 5, 2024 · 2 comments
Open
2 tasks done
Labels
API - Consistency Internal Consistency of API/Behavior Needs Discussion Requires discussion from core team before further action Usage Question Visualization plotting

Comments

@pollo-coder
Copy link

Research

  • I have searched the [pandas] tag on StackOverflow for similar questions.

  • I have asked my usage related question on StackOverflow.

Link to question on StackOverflow

https://stackoverflow.com/questions/72375976/odd-behavior-of-plotting-in-pandas

Question about pandas

I had asked this question on SO some time ago but got no satisfactory answer.

Essentially the question (slightly improved wrt what i asked on SO) was, after having imported necessary packages:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

why this code reuses the figure (so i end up with just one figure)

ser = pd.Series(np.random.randn(100))
fig = plt.figure()
ser.plot()

while this one does not (and i end up with two figures)

df  = pd.DataFrame(np.random.randn(100,3))
fig = plt.figure()
df.plot()

?

Then i debugged a little bit and noticed that this is caused by the following two lines

if isinstance(data, ABCSeries):
    kwargs["reuse_plot"] = True

in the PlotAccessor.call in pandas/pandas/plotting/_core.py around line 990

Why do we need those two lines? What is the logic behind? Could we just remove them or set kwargs["reuse_plot"] always to True? I do not see the reason for the inconsistency.

@pollo-coder pollo-coder added Needs Triage Issue that has not been reviewed by a pandas team member Usage Question labels Sep 5, 2024
@rhshadrach
Copy link
Member

rhshadrach commented Sep 9, 2024

Thanks for the report. Looks like this was introduced in #27009.

@datapythonista / @jorisvandenbossche - do you know why there is different behavior here for Series vs DataFrame? Ref: #27009 (comment)

@rhshadrach rhshadrach added Visualization plotting Needs Discussion Requires discussion from core team before further action API - Consistency Internal Consistency of API/Behavior and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 9, 2024
@pollo-coder
Copy link
Author

hi @datapythonista @jorisvandenbossche what s your view? i d be v interested!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API - Consistency Internal Consistency of API/Behavior Needs Discussion Requires discussion from core team before further action Usage Question Visualization plotting
Projects
None yet
Development

No branches or pull requests

2 participants