import numpy as np
import pandas as pan
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import csv
import datetime
timestamp1 = []
for t in ts_temp1:
timestamp1.append(mdates.datestr2num(t))
formatter = mdates.DateFormatter('%Y-%b-%d')
plt.plot_date(timestamp1,xgtemp1,'r.',label='X GALVO 1',lw=2)
plt.plot_date(timestamp1,ygtemp1,'b.',label='Y GALVO 1',lw=2)
ax = plt.gcf().axes[0]
ax.xaxis.set_major_formatter(formatter)
plt.gcf().autofmt_xdate(rotation=25)
plt.ylabel('Galvo Temperatures (°C)')
plt.grid()
plt.legend(loc='upper right')
plt.show()
我正在尝试创建一个包含3行和1列绘图的子图。 我有3块“绘图”代码与上面的代码相同。 目标是让子图中的所有绘图共享同一x轴。 我不确定如何处理这个子批次,因为我以前的许多尝试都没有成功。在
旁注:我尝试过用其他方法绘制,但这是唯一一个正确绘制时间戳的方法。在
尝试使用:
我认为直接使用}对象。对于其他子批次,请使用
Axes
对象(ax1
,ax2
,ax3
)而不是让pyplot来计算它或者提取当前的Axes
和{ax2
和ax3
或执行以下操作:fig, axn = plt.subplots(3, 1, sharex=True)
并在
axn
上循环。在另外,如果您正在使用pandas,您可以将
plot_date
命令替换为df['column'].plot(ax=ax1, lw=2)
,并跳过时间戳准备工作。在相关问题 更多 >
编程相关推荐