使用matplotlib绘制错误(无x-tick标签)

时间:2016-11-04 13:14:41

标签: python pandas matplotlib plot

我试图绘制以下pandas数据帧(第一列是索引):

          pressure mean  pressure std     Time
  Time                                          
00:00:00     618.663133      0.108484 00:00:00
01:00:00     618.281129      0.111788 01:00:00
02:00:00     617.975430      0.101657 02:00:00
03:00:00     617.766129      0.062712 03:00:00
04:00:00     617.807043      0.066030 04:00:00
05:00:00     617.976479      0.079755 05:00:00
06:00:00     618.276720      0.118224 06:00:00
.........

我的目标是绘制时间(x轴)与压力平均值(y轴)。 我希望x轴有2小时刻度和H:M格式。 我使用以下代码:

%matplotlib inline  

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import datetime
from matplotlib.ticker import MultipleLocator, FormatStrFormatter



fig = plt.figure(figsize=(15,7))
ax = fig.add_subplot(1,1,1) # row-col-num
# --- line plot data on the Axes
ax.plot(df6['Time'], df6['pressure mean'], 'b-', linewidth=2,
label=r'Hawaii Pressure')
# -- Tick Label Size --
plt.rcParams['xtick.labelsize'] = 12 
plt.rcParams['ytick.labelsize'] = 16
# -- Tick Labels Format --
DaysFmt = mdates.DateFormatter('%H:%M')
minorLocator = MultipleLocator(5)
ax.xaxis.set_minor_locator(minorLocator)
ax.xaxis.set_major_formatter(DaysFmt)

# -- Axis Labels --
ax.set_ylabel(r'Pressure $[mb]$', fontsize=22)
ax.set_xlabel(r'Hour', fontsize=22)
# -- Tick Limits and Labels --
ax.xaxis.set_major_locator(mdates.HourLocator(interval=2))              

# -- Legend and Grid --
ax.legend(loc='best')
ax.grid(True)
# -- Title --
fig.suptitle('Stacked Hourly Pressure Averages (1 month)',fontsize=27)
fig.tight_layout(pad=5)
# -- Intervals --
fig.savefig('Hawaii Stacked Pressure October 2016.png', dpi=300)

但我收到了内存错误,我知道这是因为以下几行:

ax.xaxis.set_minor_locator(minorLocator)

如果我删除该行 - 我正在获取没有任何x轴刻度标签的图表!

有什么建议吗? 谢谢!!

1 个答案:

答案 0 :(得分:0)

找到了解决方案!

我只需要将时间字符串列的转换添加到datetime:

ssh remotehost "<path to script>/myscript.sh param"

耶!