2016-12-07 3 views
0
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 개의 "플로팅"코드가 있습니다. 목표는 서브 Plot 내의 모든 플롯이 동일한 x 축을 공유하도록하는 것입니다. 이전의 많은 시도가 전혀 효과가 없었으므로이 서브 플로트에 접근하는 방법을 잘 모르겠습니다.Subplot using matplotlib.pyplot.plot_date

Sidenote : 다른 방법으로 플로팅을 시도했지만 타임 스탬프를 올바르게 표시하는 것은 이것이 유일한 방법입니다. 사용

답변

0

시도 :

fig, (ax1, ax2, ax3) = plt.subplots(3, 1, sharex=True) 

ax1.plot_date(timestamp1,xgtemp1,'r.',label='X GALVO 1',lw=2) 
ax1.plot_date(timestamp1,ygtemp1,'b.',label='Y GALVO 1',lw=2) 

ax1.xaxis.set_major_formatter(formatter) 
fig.autofmt_xdate(rotation=25) 

ax.set_ylabel('Galvo Temperatures (°C)') 
ax.grid() 
ax.legend(loc='upper right') 

fig.show() 

내가 대신 그것을 알아 내기 위해 pyplot를 얻거나 현재 AxesFigure 객체를 추출하는 Axes 객체 (ax1, ax2, ax3)로 직접 작업하는 것이 좋습니다 생각합니다. 다른 줄거리는 ax2ax3를 사용하거나 대신이 작업을 수행 할 경우 :

fig, axn = plt.subplots(3, 1, sharex=True)

및 루프를 axn 이상.

또한 팬더를 사용하는 경우 plot_date 명령을 df['column'].plot(ax=ax1, lw=2)으로 대체하고 타임 스탬프 준비 작업을 건너 뛸 수 있습니다.

+0

axn을 통해 반복되어 정상적으로 작동합니다. 감사! – Alex