我需要创建一个图表,它有一个网格,如下图所示。 关键因素是:
我已经研究matplotlib有一段时间了,它看起来很有前途。我还设法用数据填满了图表。查看40分钟数据的结果。
但在我投入更多时间进行研究之前,我必须知道这个目标是否可行。如果没有,我就得查其他图表。谢谢你的帮助!你知道吗
这是上面图片的来源(我的数据实际上是从csv读取的,但这里充满了随机垃圾):
from matplotlib import dates
import matplotlib.pyplot as plt
import numpy as np
import time
from datetime import datetime
my_data = list()
for i in range(3000):
my_data.append((datetime.fromtimestamp(i + time.time()), np.random.randint(50, 200), np.random.randint(10, 100)))
hfmt = dates.DateFormatter('%H:%M:%S')
fig = plt.figure()
actg = fig.add_subplot(2, 1, 1) # two rows, one column, first plot
plt.ylim(50, 210)
atoco = fig.add_subplot(2, 1, 2) # second plot
plt.ylim(0, 100)
actg.xaxis.set_minor_locator(dates.MinuteLocator())
actg.xaxis.set_major_formatter(hfmt)
atoco.xaxis.set_minor_locator(dates.MinuteLocator())
atoco.xaxis.set_major_formatter(hfmt)
plt.xticks(rotation=45)
times = []
fhr1 = []
toco = []
for key in my_data:
times.append(key[0])
fhr1.append(key[1])
toco.append(key[2])
actg.plot_date(times, fhr1, '-')
atoco.plot_date(times, toco, '-')
for ax in fig.axes:
ax.grid(True)
plt.tight_layout()
plt.show()
好吧,我想这和你想要的差不多。你知道吗
我用^{} 每30秒设置一次网格(还需要确保网格设置在次要刻度上,使用
ax.xaxis.grid(True,which='both')
为了重复} ,并将spine移动到该记号的位置。然后我将“脊椎颜色”(spine color)设置为“无”(none),这样它就不会显示,并且会显示实际的刻度,但不会显示刻度标签。你知道吗
yticklabels
,我为xaxis上的每个主要记号创建一个轴的^{相关问题 更多 >
编程相关推荐