我在将分散点覆盖在我的基本资料投影上时遇到麻烦。我有一组网格化的海面温度数据,正在尝试在网格化数据上绘制散点,但散点未显示。我不断收到错误消息“ ValueError:具有多个元素的数组的真值不明确。请使用
中的a.any()或a.all()”pts = m.scatter(x,y, marker='o', s=5, c=ts, cmap='plasma',latlon=True)
我的代码中的上一行。我认为它来自latlon = true。任何帮助,将不胜感激!我正在使用的数据集是netCDF文件格式。
from mpl_toolkits.basemap import Basemap, shiftgrid, cm
import numpy as np
import matplotlib.pyplot as plt
from netCDF4 import Dataset
import matplotlib as mpl
samosdata = Dataset("name of dataset", "r",format="NETCDF4")
d = Dataset("name of datas set", "r",format="NETCDF4")
sst = d.variables["analysed_sst"][:][0, ::-1, :]
lon = d.variables["lon"][:]
lat = d.variables["lat"][::-1]
lats = samosdata.variables['lat']
lons = samosdata.variables['lon']
time = samosdata.variables['time']
ts = samosdata.variables['TS']
ts = np.array(ts)
lons = np.array(lons)
lats = np.array(lats)
fig = plt.figure()
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
m = Basemap(projection='mill', llcrnrlat=-80, urcrnrlat=80,
llcrnrlon=-180, urcrnrlon=180, lat_ts=20, resolution='c')
nx = int((m.xmax - m.xmin)/11113.2); ny = int((m.ymax m.ymin)/11113.2)
sst = m.transform_scalar(sst, lon, lat, nx, ny)
im = m.imshow(sst, interpolation = "none")
x, y =m(list(lons), list(lats))
pts = m.scatter(x,y, marker='o', s=5, c=ts, cmap='plasma',latlon=True)
plt.colorbar(pts)
m.drawcoastlines()
parallels = np.arange(-90, 90, 30)
meridians = np.arange(-180, 180, 60)
m.drawparallels(parallels, labels = [1, 0, 0, 1])
m.drawmeridians(meridians, labels = [1, 0, 0, 1])
cb = m.colorbar(im, "right", size = "5%", pad = "2%")
ax.set_title("SST 2010 01 01")
plt.show()