Skip to content

Issue generating a line plot from a Series when previous plots are already defined #31086

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

Closed
RickOldenburger opened this issue Jan 16, 2020 · 2 comments
Labels

Comments

@RickOldenburger
Copy link

Code Sample, a copy-pastable example if possible

        df = self.getStats() # returns a dataFrame with a row called Rounds
        totalMatches = len(df)
        if (totalMatches == 0):
            print("Need to play at least one match for a graph", flush = True)
            return
        vc = df["Rounds"].value_counts()
        x = vc.plot(legend=True, figsize=[10, 8])
        x.set_xlabel("Number of Rounds to Win")
        x.set_ylabel("Occurrences")
        x.set_title("Value-Count Graph (Matches: " + str(totalMatches) + ")")
        
        Occurences = max(vc) + 1
        # for small values set y tic mark text
        if Occurences <= 20:
            yText = [] # Stores our Y-Axis text
            
            for i in range(1, Occurences):
                yText.append(f'${i}$')
            plt.yticks(np.arange(1, Occurences), yText, ha="center")
        
        plt.show()

The code above works fine unless the following has been executed to make "popout" graphs

%matplotlib qt5

If a previous graph exists from a previous run, and is still up. Then this graph will have additions added directly to it. Please see the images for what is happening.

Bug report for Pandas

It should be noted, I am using version 0.25.3 of pandas, and I searched and could not find this issue already logged.

  1. The reason this is an issue is that it leads to potentially different results each time the program is executed.
  2. It only occurs with pandas Series objects. (I tested and it is not an issue for dataFrames.)

You can find the full python program at:
https://github.com/RickOldenburger/War-Card-Game-Analysis

There is a work around and I have applied it in my program.
change the statement:
x = vc.plot(legend=True, figsize=[10, 8])

to these two statments:
plt.figure(figsize=(10, 8))
x = vc.plot.line(legend=True) # no point in having the figsize defined twice

Note: We receive a lot of issues on our GitHub tracker, so it is very possible that your issue has been posted before. Please check first before submitting so that we do not have to handle and close duplicates!

Note: Many problems can be resolved by simply upgrading pandas to the latest version. Before submitting, please check if that solution works for you. If possible, you may want to check if master addresses this issue, but that is not necessary.

For documentation-related issues, you can check the latest versions of the docs on master here:

https://pandas-docs.github.io/pandas-docs-travis/

If the issue has not been resolved there, go ahead and file it in the issue tracker.

Expected Output

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]

@jbrockmendel jbrockmendel added the Visualization plotting label Jan 16, 2020
@TomAugspurger
Copy link
Contributor

@RickOldenburger can you provide a minimal example when you file issues?

IIUC, the question is about Series.plot vs. DataFrame.plot different w.r.t. plotting on an existing axis. If so, that's discussed in #8776. Let me know if I misunderstood.

@RickOldenburger
Copy link
Author

RickOldenburger commented Jan 18, 2020 via email

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

No branches or pull requests

3 participants