I have these data:
If I try :
plt.plot(dates[:, 0], data)
,
I am receiving:
You can see the values on x axis are totally different from the data.
I receive the same plot with seaborn:
sns.lineplot(x=dates[:, 0],
y=data)
I want to use seaborn and have the correct x axis dates.
CodePudding user response:
The first command is iterating through the columns of dates
and plotting them against the values in data
. However, in many cases, there is no variation in the columns of dates, i.e., it's only 2016 or 2017 (plt.plot(dates[:, 4], data)
. Only when there's both values a line can be traced (plt.plot(dates[:, 5], data)
. By default, the matplotlib style doesn't have markers, so the graph looks empty (you can add marker='o'
to your plot command to show this). Also, because there's no variation in x
, matplotlib tries to give the graphs some limits to x, which ultimately end up being different from the limits when x
varied.
If you want all column graphs to have the same limits, you can specify that with plt.xlim(left=2015.7, right=2017.3)
after the plot of each individual column. Here, I put a 0.3 buffer to the left and right, but you can change this to whatever value looks better.