我使用plot_date命令在matplotlib中绘制时间序列数据。在
在下面的代码中,dt_str_etc和btotec引用日期时间格式数据的数组。我的部分代码如下:
import matplotlib.pylab as plt
import matplotlib.dates as dates
from datetime import datetime
f,axarr=plt.subplots(nrows=9,sharex=False)
axarr[0].plot_date(dt_str_16h25,BTOT16h25,fmt='-k')
axarr[1].plot_date(dt_str_16h26,BTOT16h26,fmt='-k')
axarr[2].plot_date(dt_str_16h27,BTOT16h27,fmt='-k')
axarr[3].plot_date(dt_str_16h28,BTOT16h28,fmt='-k')
axarr[4].plot_date(dt_str_16h29,BTOT16h29,fmt='-k')
axarr[5].plot_date(dt_str_16h30,BTOT16h30,fmt='-k')
axarr[6].plot_date(dt_str_16h31,BTOT16h31,fmt='-k')
axarr[7].plot_date(dt_str_16h32,BTOT16h32,fmt='-k')
axarr[8].plot_date(dt_str_16h33,BTOT16h33,fmt='-k')
现在,上面的代码起作用了。plot_date的功能如你所料,我得到了一个有9个子时隙和一个好看的时序图。。。在
我要做的是把上面的9个图绘制在一列上,而是两列上[基本上是2乘5(有一个未占用的空间)]]。一个多栏的子区。我尝试使用以下代码来执行此操作:
^{pr2}$这将返回错误:
Traceback (most recent call last):
File "C:/Users/Charles/Google Drive/Year 4 Real/MPhys Project/Mag Data/2007/Mag_data_2007_plot_T 25 26 27 28 29 30 31 32 33 adjusted.py", line 118, in <module>
axarr[1].plot_date(dt_str_16h25,BTOT16h25,fmt='-k')
AttributeError: 'numpy.ndarray' object has no attribute 'plot_date'
我只写了“ncols=2”。这是唯一的区别。为什么我不能再使用plot_date命令以这种方式绘图?在
我已经阅读了一些关于使用“add\u subplot”的子批处理matplotlib文档的信息。如果需要的话,我可以用这个重新编写代码,但我真的想保持原样。有什么想法吗?在
非常感谢您提供的任何帮助或想法。在
当打印布局有多行和多列时,返回的数组是二维的。您将需要使用
axarr[0, 0]
和axarr[0, 1]
来访问各个子批。在相关问题 更多 >
编程相关推荐