Skip to content
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

matplotlib plt.bar() function wrong signature? Version? #1

Open
bhlevca opened this issue Apr 3, 2020 · 3 comments
Open

matplotlib plt.bar() function wrong signature? Version? #1

bhlevca opened this issue Apr 3, 2020 · 3 comments

Comments

@bhlevca
Copy link

bhlevca commented Apr 3, 2020

I am unable to perform plots due to different bar() function signature.
According to this https://matplotlib.org/3.2.1/api/_as_gen/matplotlib.pyplot.bar.html the bar()
has a different implementation that what you are using.

Do you know what version are you using? Thanks

@tirthajyoti
Copy link
Owner

I am using 3.1.1.

@bhlevca
Copy link
Author

bhlevca commented Apr 4, 2020

I am using 3.1.1.

I have 3.2.1 and your code does not work. I am surprised that it allowed you to put Timestamp in the X axis. pyplot.bar does not allow this.

Also, the named parameters did not work, I had to remove them and l use positional parameters because the new implementation of pyplot.bar is like the following:

def bar(left, height, width=0.8, bottom=None, hold=None, data=None, **kwargs):

You can notice that there is no x, it was replaced by left

This code works for me:
plt.bar(dates.values, cases, color='blue', edgecolor='k')

I got inspired by your code and I created a code for Canada. Although it is substantially changed I will credit you for the initial code in the header. Thanks.

I hope to post it soon on github.com and I hope to add some analysis and predictions based on different scenarios

@bhlevca
Copy link
Author

bhlevca commented Apr 4, 2020

I suggest trying something like the code bleow that beside making it version agnostic will also simply code repetitions in your ranking method

def plot_bar(pos, cases, dt, color, title):
            labels = [val[1] for val in cases]
            x = np.arange(len(labels))  # the label locations
            axs[pos].bar(x, [val[0] for val in cases],
                       color=color, edgecolor='k')
            axs[pos].set_title("{} on {}".format(title, str(dt)),
                             fontsize=15)

            axs[pos].set_xticklabels(labels)

then call in the code like this

    ```

_, axs = plt.subplots(2, 2, figsize=(15, 9))
axs = axs.ravel()
plot_bar(0, sorted_cases, d, 'blue', "Total cases")
plot_bar(1, sorted_deaths, d, 'red', "Total deaths")
plot_bar(2, sorted_newcases, d, 'yellow', "New cases")
plot_bar(3, sorted_newdeaths, d, 'orange', "New deaths")

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

No branches or pull requests

2 participants