我正在尝试使用我设置的频率创建一个带有刻度的x轴,以便我的所有数字看起来都一样。我有一个534个日期时间值的数组,称为summertime,我试图在那些日期时间之间制作x轴,频率为10.
ax1.xaxis.set_ticks( np.arange(summertime.min(), summertime.max(), 10))
代码在崩溃之前运行了几天,而我正在更改变量等。没有错误出现,只是说它运行了一段时间然后导致内核崩溃。此外,看起来它正在耗尽我的计算机上的大部分内存来运行它。在尝试运行时,我看到它燃烧了20gb。
不完全确定发生了什么,但非常喜欢有关如何修复此错误的建议。
Ran the code. Been waiting 2 min. Memory jumped from 54% to 92%. Whole computer slowing down
答案 0 :(得分:0)
语法没有错。问题可能是范围summertime.max() - summertime.min()太大了。
我刚刚执行了
ax4.xaxis.set_ticks(np.arange(0.5,100,10))
在我的电脑上运行正常。但是如果我执行
ax4.xaxis.set_ticks(np.arange(0.5,100000000,10))
它给了我内存错误。
您能否分享一下夏季数据框的信息。
答案 1 :(得分:0)
显然,当你打电话
np.arange(summertime.min(), summertime.max(), 10)
该值10
的单位是datetime
对象的最小单位,微秒。鉴于您的开始和结束日期,对arange
的调用正在尝试创建长度为198707200000的数组。这将需要超过1TB的内存。
你说“我试图在频率为10的那个日期时间之间制作x轴”,但是你没有说出那个10的值的单位是多少。 10分钟?小时?秒?
假设这是10个小时。您可以将该增量指定为微秒数,或者指定为datetime.timedelta
对象。例如,
In [43]: mn = datetime.datetime(2015, 7, 24, 0, 10, 40)
In [44]: mx = datetime.datetime(2015, 8, 16, 0, 8, 32)
In [45]: np.arange(mn, mx, 10*3600*1000000) # Increment is 10 hours, expressed in microseconds
Out[45]:
array(['2015-07-24T00:10:40.000000', '2015-07-24T10:10:40.000000',
'2015-07-24T20:10:40.000000', '2015-07-25T06:10:40.000000',
'2015-07-25T16:10:40.000000', '2015-07-26T02:10:40.000000',
'2015-07-26T12:10:40.000000', '2015-07-26T22:10:40.000000',
'2015-07-27T08:10:40.000000', '2015-07-27T18:10:40.000000',
'2015-07-28T04:10:40.000000', '2015-07-28T14:10:40.000000',
'2015-07-29T00:10:40.000000', '2015-07-29T10:10:40.000000',
'2015-07-29T20:10:40.000000', '2015-07-30T06:10:40.000000',
'2015-07-30T16:10:40.000000', '2015-07-31T02:10:40.000000',
'2015-07-31T12:10:40.000000', '2015-07-31T22:10:40.000000',
'2015-08-01T08:10:40.000000', '2015-08-01T18:10:40.000000',
'2015-08-02T04:10:40.000000', '2015-08-02T14:10:40.000000',
'2015-08-03T00:10:40.000000', '2015-08-03T10:10:40.000000',
'2015-08-03T20:10:40.000000', '2015-08-04T06:10:40.000000',
'2015-08-04T16:10:40.000000', '2015-08-05T02:10:40.000000',
'2015-08-05T12:10:40.000000', '2015-08-05T22:10:40.000000',
'2015-08-06T08:10:40.000000', '2015-08-06T18:10:40.000000',
'2015-08-07T04:10:40.000000', '2015-08-07T14:10:40.000000',
'2015-08-08T00:10:40.000000', '2015-08-08T10:10:40.000000',
'2015-08-08T20:10:40.000000', '2015-08-09T06:10:40.000000',
'2015-08-09T16:10:40.000000', '2015-08-10T02:10:40.000000',
'2015-08-10T12:10:40.000000', '2015-08-10T22:10:40.000000',
'2015-08-11T08:10:40.000000', '2015-08-11T18:10:40.000000',
'2015-08-12T04:10:40.000000', '2015-08-12T14:10:40.000000',
'2015-08-13T00:10:40.000000', '2015-08-13T10:10:40.000000',
'2015-08-13T20:10:40.000000', '2015-08-14T06:10:40.000000',
'2015-08-14T16:10:40.000000', '2015-08-15T02:10:40.000000',
'2015-08-15T12:10:40.000000', '2015-08-15T22:10:40.000000'], dtype='datetime64[us]')
In [46]: np.arange(mn, mx, datetime.timedelta(hours=10)) # Increment is 10 hours, expressed using a datetime.timedelta
Out[46]:
array(['2015-07-24T00:10:40.000000', '2015-07-24T10:10:40.000000',
'2015-07-24T20:10:40.000000', '2015-07-25T06:10:40.000000',
'2015-07-25T16:10:40.000000', '2015-07-26T02:10:40.000000',
'2015-07-26T12:10:40.000000', '2015-07-26T22:10:40.000000',
'2015-07-27T08:10:40.000000', '2015-07-27T18:10:40.000000',
'2015-07-28T04:10:40.000000', '2015-07-28T14:10:40.000000',
'2015-07-29T00:10:40.000000', '2015-07-29T10:10:40.000000',
'2015-07-29T20:10:40.000000', '2015-07-30T06:10:40.000000',
'2015-07-30T16:10:40.000000', '2015-07-31T02:10:40.000000',
'2015-07-31T12:10:40.000000', '2015-07-31T22:10:40.000000',
'2015-08-01T08:10:40.000000', '2015-08-01T18:10:40.000000',
'2015-08-02T04:10:40.000000', '2015-08-02T14:10:40.000000',
'2015-08-03T00:10:40.000000', '2015-08-03T10:10:40.000000',
'2015-08-03T20:10:40.000000', '2015-08-04T06:10:40.000000',
'2015-08-04T16:10:40.000000', '2015-08-05T02:10:40.000000',
'2015-08-05T12:10:40.000000', '2015-08-05T22:10:40.000000',
'2015-08-06T08:10:40.000000', '2015-08-06T18:10:40.000000',
'2015-08-07T04:10:40.000000', '2015-08-07T14:10:40.000000',
'2015-08-08T00:10:40.000000', '2015-08-08T10:10:40.000000',
'2015-08-08T20:10:40.000000', '2015-08-09T06:10:40.000000',
'2015-08-09T16:10:40.000000', '2015-08-10T02:10:40.000000',
'2015-08-10T12:10:40.000000', '2015-08-10T22:10:40.000000',
'2015-08-11T08:10:40.000000', '2015-08-11T18:10:40.000000',
'2015-08-12T04:10:40.000000', '2015-08-12T14:10:40.000000',
'2015-08-13T00:10:40.000000', '2015-08-13T10:10:40.000000',
'2015-08-13T20:10:40.000000', '2015-08-14T06:10:40.000000',
'2015-08-14T16:10:40.000000', '2015-08-15T02:10:40.000000',
'2015-08-15T12:10:40.000000', '2015-08-15T22:10:40.000000'], dtype='datetime64[us]')