I'm analyzing coronavirus data in my country and I want to plot the data on new deaths, and total deaths in one plot. Initially I plotted it using the inbuilt plot
function on the dataframe.
reports.plot(x='date', y='new_deaths')
reports.plot(x='date', y='total_deaths')
plt.xlabel('date')
plt.ylabel('cases')
plt.show()
However, I wanted to change the legends, and have them to be in one plot instead so I went ahead and used plt.subplot(111)
.
fig = plt.figure()
ax = plt.subplot(111)
ax.plot(ph_reports_april.date, ph_reports_april.new_deaths, label='New Deaths')
ax.plot(ph_reports_april.date, ph_reports_april.total_deaths, label='Total Deaths')
plt.xlabel('Date')
plt.ylabel('Cases')
ax.legend()
plt.show()
It got the job done except for one little problem.
The dates are congested. Is there a way to have the date similar to how the dataframe.plot()
function works? I've browse through this site and haven't found anything of value regarding on spacing out the values of date in the x-axis.