绘制一年中的几天Python

2024-09-29 17:22:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着画出时间(x轴)和流动(y轴)。我的数据系列“时间”是一年中的几天,但它从1到365。有没有办法让图显示在x轴上的天/月(所以1月1日是1-1,2月1日是1-2,…,12月1日是1-12),而不是1,2,3,4,5一直到365天?还是需要添加另一列日期?在

from matplotlib import pyplot
enter code from matplotlib import pyplot
from math import log
time = list(mom6[0])
flow = list(mom6[1])
pyplot.scatter(x,y,linestyle = '--')
pyplot.ylabel('Flow (cfs)')
pyplot.xlabel('Time')
pyplot.title('Flow Duration')
pyplot.yscale('log')
plt.grid(True)
plt.show()here

也是为了散点图(x,y,linestyle='-')它不会连接点。我的数组看起来像:

^{pr2}$

最佳


Tags: 数据fromimportlogmatplotlib时间codeplt
1条回答
网友
1楼 · 发布于 2024-09-29 17:22:25

可以使用datetime进行转换:

(用于在time = list(mom6[0])之后插入):

import datetime
start = datetime.date(2015, 1, 1)
dts = [ start + datetime.timedelta(days=int(ea)-1) for ea in time ]
time = [ ea.strftime('%d-%m') for ea in dts ]

结果:

^{pr2}$

相关问题 更多 >

    热门问题