Python 关于x轴上的重叠

Python 关于x轴上的重叠,python,pandas,matplotlib,Python,Pandas,Matplotlib,这是我的数据 Timeseries CCN Number Conc SS 0 00:00:00 15.810967 0.1 1 00:05:00 358.401000 0.3 2 00:10:00 797.538333 0.5 3 00:15:00 1017.533267 0.7 4 00:20:00 1097.861700 0.9 ... ... ... ... 283 23:35:00 675.185867 0.3 284

这是我的数据

Timeseries  CCN Number Conc SS
0   00:00:00    15.810967   0.1
1   00:05:00    358.401000  0.3
2   00:10:00    797.538333  0.5
3   00:15:00    1017.533267 0.7
4   00:20:00    1097.861700 0.9
... ... ... ...
283 23:35:00    675.185867  0.3
284 23:40:00    1358.752733 0.5
285 23:45:00    1604.543000 0.7
286 23:50:00    1724.583433 0.9
287 23:55:00    489.555633  0.1
下面是我的代码:

将熊猫作为pd导入
将matplotlib.pyplot作为plt导入
将numpy作为np导入
加载\u file=pd.read\u excel(r'E:\CCNC\CCNCCodes\Modulated output\Copy of
最终\u调制\u ccnc\u数据.xlsx',标头=0)
加载文件.columns
s=load_file.loc[0:289,['Timeseries','CCN Number Conc','SS']
s
s1=s
s['Timeseries']=s['Timeseries'].astype(str)
plt.plot(s1[0:289]['Timeseries',s1[0:5762]['CCN Number Conc'],color='b')
plt.show()
plt.plot(s1[0:289]['Timeseries',s1[0:5762]['CCN Number Conc'])
plt.setp(s.getxticklabels(),旋转=30,水平对齐='right')
图1紧_布局图()
plt.xlabel(“以分钟为单位的时间”)
plt.xticks(旋转=90)
plt.ylabel(“云凝结数”)
plt.title(“云凝结数Vs时间序列(5min)”)
plt.紧_布局()
plt.gcf().autofmtxDate()
plt.show()
以下是我的输出图像:

请告诉我需要在何处进行更改以避免时间序列在x轴上重叠。

您可以使用并更改x轴刻度的外观

由于每5分钟的显示频率太高,无法表示,因此我将按
HourLocator()
设置的每小时减少主刻度显示。相反,次要滴答声的间隔设置为5分钟

导入matplotlib.pyplot作为plt
将matplotlib.dates导入为mdates
作为pd进口熊猫
加载文件=pd.read\u csv(r'1.csv')
s=加载文件
#将字符串转换为日期时间
s['Timeseries']=pd.to_datetime(s['Timeseries'])
图,ax=plt.子批次()
ax.plot(s['Timeseries',s['CCN Number Conc',color='b')
#设置时间格式
xformatter=mdates.DateFormatter(“%H:%M”)
xMajorLocator=mdates.HourLocator()
#设置滴答声的间隔(每5分钟一次)
xMinorLocator=mdates.MinuteLocator(byminute=range(5,60,5),interval=1)
ax.xaxis.set\u major\u定位器(xMajorLocator)
ax.xaxis.set\u major\u格式化程序(xformatter)
ax.xaxis.set_minor_定位器(xMinorLocator)
plt.xlabel(“以分钟为单位的时间”)
plt.ylabel(“云凝结数”)
plt.title(“云凝结数Vs时间序列(5min)”)
plt.紧_布局()
plt.gcf().autofmtxDate()
plt.show()


您不能直接运行此脚本。如果您对我如何生成数据感兴趣,可以从[print(datetime.datetime.now().replace(hour=0,minute=0,second=0)+datetime.timedelta(minutes=I*5)]中修改数据,以获得范围(24*12)内的I值。

这有帮助吗:?没有,这没有帮助