Somu Nath
Somu Nath

Reputation: 33

from a series of datetimes, how to downsample and select less number of dates and put them in the x labels and xticks?

i am making a plot on which the x axis represents dates and the y axis represents total covid cases. the problem is that due to a large dataset, there are many dates on the x axis and when i am ploting that i am getting a plot on which the xtick values are overlapped and i can not clearly see the covid cases at a particular date. so i want to make a clear graph. how can i do that? or you can also suggest me any better idea to make the graph more readable. i am giving my code and plot below. Thanks. my plot

Upvotes: -1

Views: 239

Answers (1)

Rob Raymond
Rob Raymond

Reputation: 31146

x = countries["date"]
y = countries["total_cases"]

fig, ax = plt.subplots(figsize=(10, 6))
locator = mdates.AutoDateLocator(minticks=3, maxticks=7)
formatter = mdates.ConciseDateFormatter(locator)
ax.xaxis.set_major_locator(locator)
ax.xaxis.set_major_formatter(formatter)
ax.plot(x, y)

enter image description here

Upvotes: 1

Related Questions