Home > Back-end >  How to reduce ticks?
How to reduce ticks?

Time:11-20

I have 250 rows of data, it starts january 2002 and ends septemper 2022 and interwal per row is one row/one month of the year.

enter image description here

Now i want to plot it but it takes all 250 rows and plot it and i only want like one year shown per tick

The y axis is float and x axis is string

I have saw that you have to label them manualy but what if i have like realy big data? There must be some efficient way.

i have tried something like this:

import matplotlib.pyplot as plt

X = df_polt['Päivä']
y = df_polt['Diesel']

fig, ax = plt.subplots(1,1,figsize=(15, 10)) 
ax.plot(X, y)

I want that X axis is like 10 ticks

enter image description here

CodePudding user response:

I believe if you used xticks you'll be fine https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.xticks.html

plt.xticks([0, 365, 730], ['2001', '2002', '2003'],rotation=0)

An approach like this one is what I propose, you can always customize and/or make it automatic.

edit: I assumed that you have data for each day (this affects the points where you add a tick, change it according to your dataset).

CodePudding user response:

Untested.

plt.plot(df_polt['Diesel'])
plt.xticks(range(0,241,24))
plt.xticklabels(["%d-01"%y for year in range(2002,2023,2)])
  • Related