I want to plot a pandas dateframe with defined ticks.
As it can be seen in the plot the time distance between ticks is 8 minutes and 20 seconds. I would like to have this in 5 Minute steps.
The data is a dataframe with the following structure:
Data1 Data2
timestamps
0 days 00:00:00 36.59338 36.465206
0 days 00:00:00.100000 36.59338 36.465206
0 days 00:00:00.200000 36.59338 36.465206
0 days 00:00:00.300000 36.59338 36.465206
0 days 00:00:00.400000 36.59338 36.465206
How can I control the step size of the ticks in the example?
The code:
df.plot(color=colors);
Leads to the above Picture.
df.plot()
fortunately returns a matplotlib.AxesSubplot
so you can change paramaters as you would usually do. Also, to properly define datetime xticks, you should use the matplotlib.dates
package.
import matplotlib.pyplot as plt
import matplotlib.dates as md
ax = df.plot(color=colors)
min_time = df.index.minute.min
max_time = df.index.minute.max
time_int = 5
xlocator = md.MinuteLocator(byminute=np.arange(min_time, max_time+1, time_int), interval = 1)
ax.xaxis.set_major_locator(xlocator)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.