我正在尝试使用以下代码来可视化聚类数据集:
import pandas as pd
import numpy as np
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
from pylab import rcParams
from sklearn.cluster import DBSCAN
from sklearn.preprocessing import StandardScaler
import sklearn.utils
sklearn.utils.check_random_state(1000)
pdf = pd.read_csv("weather-stations20140101-20141231.csv")
#print(pdf.head())
print(pdf["Tm"])
pdf = pdf[pd.notnull(pdf["Tm"])]
pdf = pdf.reset_index(drop = True)
print(pdf["Tm"])
rcParams['figure.figsize'] = (14,10)
llon=-140
ulon=-50
llat=40
ulat=65
pdf = pdf[(pdf['Long'] > llon) & (pdf['Long'] < ulon) & (pdf['Lat'] > llat) &(pdf['Lat'] < ulat)]
my_map = Basemap(projection='merc',
resolution = 'l', area_thresh = 1000.0,
llcrnrlon=llon, llcrnrlat=llat, #min longitude (llcrnrlon) and latitude (llcrnrlat)
urcrnrlon=ulon, urcrnrlat=ulat) #max longitude (urcrnrlon) and latitude (urcrnrlat)
my_map.drawcoastlines()
my_map.drawcountries()
# my_map.drawmapboundary()
my_map.fillcontinents(color = 'white', alpha = 0.3)
my_map.shadedrelief()
xs,ys = my_map(np.asarray(pdf.Long), np.asarray(pdf.Lat))
pdf['xm']= xs.tolist()
pdf['ym'] =ys.tolist()
#Visualization1
for index,row in pdf.iterrows():
# x,y = my_map(row.Long, row.Lat)
my_map.plot(row.xm, row.ym,markerfacecolor =([1,0,0]), marker='o', markersize= 5, alpha = 0.75)
#plt.text(x,y,stn)
plt.show()
这是错误:
Traceback (most recent call last):
File "<ipython-input-24-2a554ff5eafe>", line 1, in <module>
runfile('D:/Suv/Work/MLIBM/dbscan_realData.py', wdir='D:/Suv/Work/MLIBM')
File "C:\Users\dev_f\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 786, in runfile
execfile(filename, namespace)
File "C:\Users\dev_f\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "D:/Suv/Work/MLIBM/dbscan_realData.py", line 10, in <module>
from mpl_toolkits.basemap import Basemap
File "C:\Users\dev_f\Anaconda3\lib\site-packages\mpl_toolkits\basemap\__init__.py", line 42, in <module>
from mpl_toolkits.axes_grid1 import make_axes_locatable
File "C:\Users\dev_f\Anaconda3\lib\site-packages\mpl_toolkits\axes_grid1\__init__.py", line 2, in <module>
from .axes_divider import Divider, SubplotDivider, LocatableAxes, \
File "C:\Users\dev_f\Anaconda3\lib\site-packages\mpl_toolkits\axes_grid1\axes_divider.py", line 848, in <module>
addendum=' There is no alternative. Deriving from '
TypeError: deprecated() missing 5 required keyword-only arguments: 'message', 'name', 'alternative', 'pending', and 'obj_type'
我刚刚使用anaconda提示符通过以下命令安装了“底图”软件包:conda install -c conda-forge basemap
在安装底图之前,我遇到找不到模块错误。
那么有人可以帮助我了解错误是什么以及是否有其他方法来安装/更新底图软件包吗?
我正在Windows 10上运行Spyder(Python 3.7)。