Stuck trying to change x ticks on lineplot

I feel like in this instance a picture is worth a thousand words. You can see that there is a problem when I try to change the x ticks. I can see that the graph is all on the right side and the ticks all on the left. That makes me guess the range is very wide in the second chart. So my plotted x-ticks are on the lowest end of the range and the graph is on the highest end of the range. Maybe I could create a year column using .dt.year but surely there’s a way to do this without making a new column. Thanks for any help.

try this:

yourlist = [2000, 2005,...., 2020]
ax.set_xticks(list(range(len([yourlist])))
ax.set_xlabels([yourlist])

Hi Adam. That made me try using fig, ax = plt.subplots() instead of plt.plot(). And opened up a can of datetime worms. When I tried the code you suggest I get:
ValueError: DateFormatter found a value of x=0, which is an illegal date; this usually occurs because you have not informed the axis that it is plotting dates, e.g., with ax.xaxis_date()
So I went looking and have made some progress. See attached image. If I try ax.set_xticks([2000, 2005, 2010, 2015, 2020]) I get the same bunched up graph. But if I leave that out I get the correct image.

I just need to pay homage to matplotlib documentation and stackoverflow for long enough to get it to work.

Also, I was looking for a geopandas project and I’m going to try to use this one. I have an idea I’ve poked at and once I get this figured out I have a couple of questions about that. I already have my .shp file and I’ve filled some maps.

there’s an easy fix for the above pic:

X_TICKS = 2 
plt.xticks(range(0, len(df['windspeed'].sort_values().unique()), X_TICKS), df['windspeed'].sort_values().unique()[::X_TICKS], rotation = 0)

just change df[‘windspeed’] to the pd.Series you’re using , and X_TICKS to the number of your preference

you probably can skip ‘unique’ (I am assuming you have 1 row per date)