底图TypeError:输入必须是数组,列表,元组或标量

时间:2019-01-23 01:44:41

标签: python python-3.x pandas matplotlib matplotlib-basemap

我正在尝试使用Python 3.0中的basemap模块来创建地图可视化,但是当我尝试绘制该图形时,出现TypeError:

TypeError: input must be an array, list, tuple or scalar

我的代码如下:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap

data = pd.ExcelFile('C:\\Users\\...xlsx')
data_input = pd.read_excel(data, 'Sheet2')

# Extract the data we're interested in
lat = data_input['value1'].values
lon = data_input['value2'].values
capacity = data_input['value3'].values

# 1. Draw the map background
fig = plt.figure(figsize=(8, 8))
m = Basemap(projection='lcc', resolution='h', 
            lat_0=31.1351682, lon_0=-99.3350553,
            width=1.3E6, height=1.25E6)
m.shadedrelief()
m.drawcoastlines(color='gray')
m.drawcountries(color='gray')
m.drawstates(color='gray')

# 2. scatter city data, with color reflecting population
# and size reflecting area
m.scatter(lon, lat, latlon=True,
          c=np.log10(capacity), s=capacity,
          cmap='Reds', alpha=0.5)

我尝试将所有输入更改为data_input.valuesdata_input.to_list()list(data_input),并且仅使用默认的熊猫系列。

错误回溯发生在这里:

  File "<ipython-input-6-3a66206674c7>", line 3, in <module>
    cmap='Reds', alpha=0.5)

  File "C:\Users\...Continuum\anaconda3\lib\site-packages\mpl_toolkits\basemap\__init__.py", line 566, in with_transform
    x, y = self(x,y)

  File "C:\Users\...\Continuum\anaconda3\lib\site-packages\mpl_toolkits\basemap\__init__.py", line 1191, in __call__
    xout,yout = self.projtran(x,y,inverse=inverse)

  File "C:\Users\...\Continuum\anaconda3\lib\site-packages\mpl_toolkits\basemap\proj.py", line 288, in __call__
    outx,outy = self._proj4(x, y, inverse=inverse)

  File "C:\Users\...\Continuum\anaconda3\lib\site-packages\pyproj\__init__.py", line 397, in __call__
    inx, xisfloat, xislist, xistuple = _copytobuffer(lon)

  File "C:\Users\...\Continuum\anaconda3\lib\site-packages\pyproj\__init__.py", line 652, in _copytobuffer

    raise TypeError('input must be an array, list, tuple or scalar')

无论采用什么形式,它都行不通。我在这里想念什么?

0 个答案:

没有答案