如何使两行从不同的点开始(Python)

2024-04-25 14:35:41 发布

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

这就是我想要达到的目标

enter image description here

txt文件:

时间戳、辐照度、环境温度 21/7/2014 0:00,0.66,29.16 2014年7月21日0:00,0.71,29.16

通过使用以下代码,我可以使一个图形从15开始,而不是从0开始,并将限制限制限制为40:

ax1.set_ylim(15,40)

如何编写另一行从0开始的代码

谢谢

编辑

t = [datetime.strptime(x, '%d/%m/%Y %H:%M') for x in t ]
temp = [float(x) for i,x in enumerate(temp) if startTime<=t[i]<=endTime]

t = [x for x in t if startTime<=x<=endTime]

fig = plt.figure()
ax1 = fig.add_subplot(1, 1, 1, axisbg='white')
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%H:%M'))
ax1.set_ylim(15,40)
ax1.plot(t, temp, 'c', linewidth=3.3)


short_title = ('Ambient Temperature vs. Time Graph \n From {} To {} \n ')
long_title = ('\n Max AMB_TEMP Value: {:.2f} at {} , Min AMB_TEMP Value: {:.2f} at {}, Mean AMB_TEMP Value: {:.2f} at {}\n')
fig.suptitle(short_title.format(startTime, endTime), fontsize=20, color='blue')   ax1.set_title(long_title.format(max(y),min(y),fontsize=16, color='green', ha='bottom'))
plt.ylabel(u'Ambient Temperature(\u2103)', fontsize=16, color='blue')
plt.xlabel('Time ($H:M$)', fontsize=16, color='blue')
fig.tight_layout()
plt.show()

Tags: infortitlevaluefigplttempcolor
1条回答
网友
1楼 · 发布于 2024-04-25 14:35:41

您可能需要创建两个不同的y轴(不必使第二个y轴可见),如下例所示: http://matplotlib.org/examples/api/two_scales.html

您还可以通过向其中一条曲线的所有值添加/减去常量来移动值,这将分别移动曲线。垂直向上/向下。你知道吗

相关问题 更多 >