Issue
I'm trying to plot some date in matplotlib:
plt.ylabel("Word Frequency")
plt.xlabel("Date")
x_values = [datetime.datetime.strptime(key,"%Y-%m-%d").date() for key in final]
y_values = [9,2,9,4,5,6,7,8,9]
plt.xticks(rotation=90)
plt.plot(x_values,y_values)
plt.show()
This code is quite simple, but the result is seriously odd-looking:
When I did a print(x_values)
, I got :
[datetime.date(2021, 4, 28), datetime.date(2021, 4, 20), datetime.date(2021, 5, 8), datetime.date(2021, 4, 29), datetime.date(2021, 4, 14), datetime.date(2021, 5, 11), datetime.date(2021, 5, 4), datetime.date(2021, 4, 26), datetime.date(2021, 5, 2)]
And these values don't even reassemble the values plotted.
Solution
Mainly un-sorted list was the problem:
x_values = [datetime.datetime.strptime(key,"%Y-%m-%d").date() for key in final]
x_values.sort()
y_values = [9,2,9,4,5,6,7,8,9]
Answered By - Maifee Ul Asad
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.