matplotlib plt.bar() function wrong signature? Version?
bhlevca opened this issue · comments
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
I am using 3.1.1.
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
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")