0

我想将阈值线(水平虚线红线)设置为具有不同值的多个子图。

图 1 阈值应为 5000,图 2 阈值应为 4000,图 3 阈值应为 3000,图 4 阈值应为 4000。

import matplotlib.pyplot as plt
from matplotlib import style
import pandas as pd
import matplotlib.dates as md


读取 csv 文件以绘制图形

datargraph1 = pd.read_csv('REPORT1.csv')
datargraph2 = pd.read_csv('REPORT2.csv')
datagraph3 = pd.read_csv('REPORT3.csv')
datagraph4 = pd.read_csv('REPORT4.csv')

在这里,我试图隐藏熊猫日期时间系列中的列

datargraph1['Timestamp'] = pd.to_datetime(datargraph1['Timestamp'], format='%H%M%S')
datargraph2['Timestamp'] = pd.to_datetime(datargraph2['Timestamp'], format='%H%M%S')
datagraph3['Timestamp'] = pd.to_datetime(datagraph3['Timestamp'], format='%H%M%S')
datagraph4['Timestamp'] = pd.to_datetime(datagraph4['Timestamp'], format='%H%M%S')

将 ylimits 设置为不同的轴

style.use('ggplot')
fig, axes = plt.subplots(ncols=4)


axes[0].title.set_text('Graph 1')

axes[0].set_ylim([0,8000])
axes[0].axhline( y=5000, xmin=0, xmax=1)


axes[1].title.set_text('Graph 2')
axes[1].set_ylim([0,6000])


axes[2].title.set_text('Graph 3')

axes[2].set_ylim([0,6000])

axes[3].title.set_text('Graph 4')


axes[3].set_ylim([0,6000])

为 24 小时制定义 x 轴

axes[0].xaxis.set_major_locator(md.HourLocator(interval=1))
axes[0].xaxis.set_major_formatter(md.DateFormatter('%H:%M:%S'))


axes[1].xaxis.set_major_locator(md.HourLocator(interval=1))
axes[1].xaxis.set_major_formatter(md.DateFormatter('%H:%M:%S'))

axes[2].xaxis.set_major_locator(md.HourLocator(interval=1))
axes[2].xaxis.set_major_formatter(md.DateFormatter('%H:%M:%S'))

axes[3].xaxis.set_major_locator(md.HourLocator(interval=1))
axes[3].xaxis.set_major_formatter(md.DateFormatter('%H:%M:%S'))

axes[0].plot(datargraph1['Timestamp'], datargraph1['CurrentCPS'], color='b')

axes[1].plot(datargraph2['Timestamp'], datargraph2['CurrentCPS'], color='r')
axes[2].plot(datagraph3['Timestamp'], datagraph3['CurrentCPS'], color='g')
axes[3].plot(datagraph4['Timestamp'], datagraph4['CurrentCPS'], color='y')





plt.show()



但我收到错误

定位器尝试从 691587.6916666667 到 735781.8166666667 生成 1060660 个刻度:超过 Locator.MAXTICKS

在此处输入图像描述

4

0 回答 0