【问题标题】:Getting memory error while using excel data使用excel数据时出现内存错误
【发布时间】:2020-08-05 13:07:13
【问题描述】:

我正在尝试使用 excel 中的数据绘制等高线图。但是我收到错误消息“MemoryError: Unable to allocate 55.6 GiB for an array with shape (86400, 86400) and data type float64”。如果有人可以通过展示如何解决这个问题并绘制数据来帮助我,我们将不胜感激。下面我附上我的代码以及指向 excel 数据的链接。

import numpy as np
from netCDF4 import num2date
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap,shiftgrid
import seaborn as sns
import pandas as pd

df = pd.read_excel('E:/Super_cyclone/Datasets/tchp/2007_tchp/tchp_2007.xlsx')
x = df.Lon.values
y = df.Lat.values
plt_data = df.TCHP.values

fig = plt.figure(figsize=[7.5,7.5])  # a new figure window
ax = fig.add_subplot(1, 1, 1)
map = Basemap(projection='merc',llcrnrlat=5,urcrnrlat=30,\
        llcrnrlon=50,urcrnrlon=80, resolution='i', ax=ax)
map.drawcoastlines()
map.fillcontinents(color='#ffe2ab')

map.drawparallels(np.arange(5.,31.,5.),labels=[1,0,0,0])
map.drawmeridians(np.arange(50.,81.,5.),labels=[1,1,0,1])

#data,lons = shiftgrid(180.,data,lons,start=False)
llons, llats = np.meshgrid(x, y)
lon,lat = map(llons,llats)

plt.style.use('seaborn-white')
#clevels=np.arange(24,32.1,0.5)
cs = map.contourf(x,y,plt_data,cmap=plt.cm.jet)#,clevels,cmap=plt.cm.jet)

TCHP

【问题讨论】:

  • 也向我们展示回溯。哪一行产生 MemoryError?
  • @AKX 回溯如下:“回溯(最近一次调用最后一次):文件“”,第 24 行,在 llons,llats = np. meshgrid(x, y) 文件“<__array_function__ internals>”,第 6 行,在 meshgrid 文件“C:\Users\Debashis Paul\Anaconda3\lib\site-packages\numpy\lib\function_base.py”,第 4209 行,在meshgrid 输出 = [x.copy() for x in output] 文件“C:\Users\Debashis Paul\Anaconda3\lib\site-packages\numpy\lib\function_base.py”,第 4209 行,在 输出 = [x.copy() for x in output]
  • 对,所以将这些数字传递给meshgrid 它正在尝试创建一个...非常大的数组。你的算法可能有问题。
  • @AKX 你能帮我如何绘制它,我是 python 新手。

标签: python pandas matplotlib contourf


【解决方案1】:

尝试将数据集拆分为多个较小的 Excel 文件。

【讨论】:

  • 但是如果我拆分是否可以绘制整个区域。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-06-02
  • 1970-01-01
  • 1970-01-01
  • 2011-12-08
  • 2021-06-07
  • 1970-01-01
  • 2018-09-02
相关资源
最近更新 更多