Вот мой код:
# Graph for both infections and closures
# # plotting the points
plt.plot(graph_date, graph_daily_infections, label = "Infections per day")
plt.plot(graph_date, graph_total_infections, label = "Infection overall")
plt.plot(graph_date, graph_daily_closure, label = "Closures per day")
plt.plot(graph_date, graph_total_closure, label = "Closure overall")
# # naming the x axis
plt.xlabel('Date')
# naming the y axis
plt.ylabel('Number of Infections/Closure')
# giving a title to my graph
plt.title('Daily infections and closure overtime \n Infection Rate: {0} | Closure Threshold: {1}'.format(infectionRate,closeThreshold))
# show a legend on the plot
plt.legend()
# # changing the scale of the x ticks at the bottom
# # plt.locator_params(nbins=4)
# # set size of the graph
plt.rcParams["figure.figsize"] = (20,15)
# # function to show the plot
plt.show()
Проблема с этим кодом заключается в том, что даты отображаются вместе на оси х, когда они отображаются. См. Ниже:
Есть ли способ показать только месяцы или показать только месяцы и годы? интервал, для которого на графике должны отображаться данные, составляет 4 месяца, поэтому идеальным будет показывать только месяцы / год и месяц. Спасибо!