【发布时间】:2021-04-29 14:07:54
【问题描述】:
我想使用 cartopy 将多个站点从 txt 文件散点到地图上:
def ReadData(FileName,typee,delimee):
return np.genfromtxt(FileName, dtype=typee, delimiter=delimee, encoding='latin-1')
MyTypes = ("|U11","float","float","float","|U1","|U2","|U1","|U29")
MyDelimiters = [11,9,10,7,1,2,1,29] # station ID, lat, lon (-180 to 180), elevation (m), blank, Country code, blank, Name
RawData = ReadData(stations.txt,MyTypes,MyDelimiters)
stations.txt:
01001099999 70.9330 -8.6670 9.0 NO JAN MAYEN(NOR-NAVY) 0100109
01001599999 61.3830 5.8670 327.0 NO BRINGELAND 0100159
01003099999 77.0000 15.5000 12.0 NO HORNSUND 0100309
01008099999 78.2460 15.4660 26.8 SV LONGYEAR 0100809
01010099999 69.2930 16.1440 13.1 NO ANDOYA 0101009
第 2 列代表纬度,第 3 列代表经度,第 4 列代表海拔。
StationListID = np.array(RawData['f0'])
StationListLat = np.array(RawData['f1'])
StationListLon = np.array(RawData['f2'])
StationListElev = np.array(RawData['f3'])
我用:
import matplotlib.pyplot as plt
import cartopy.crs as crs
plt.scatter(x=StationListLon, y=StationListLat,
color="dodgerblue",
s=1,
alpha=0.5,
transform=crs.PlateCarree())
如果海拔 5 绿色,> 10 红色和 > 15 蓝点。在哪里设置 if 条件或对行进行分组?
【问题讨论】:
-
我的回答对你有帮助吗?
-
非常感谢您的帮助,Ruthger!你的代码有效,是的。我正在通过
RawData = ReadData(InList,MyTypes,MyDelimiters)读取数据,RawData['colors'] = pd.cut(RawData['f3'], bins=cut_bins, labels=color_labels)给了我ValueError: no field of name colors。 -
很难看出发生了什么。您能否更新您的问题并添加您采取的所有步骤并显示
RawData.head()在每个步骤之后给出的内容? -
也许已经存在错误:
RawData.head()就在StationListElev = np.array(RawData['f3'])给我*** AttributeError: 'numpy.ndarray' object has no attribute 'head'之后。我的 RawData 看起来像这样,如果我不将 x f1 f2 f3 站添加到我的 ASCII 文件的第一行:[('01001099999', 70.933, -8.667, 9. , ' ', 'NO', ' ', 'JAN MAYEN(NOR-NAVY) ') ... ("''''\n", nan, nan, nan, '', '', '', '')] -
type(RawData)在ReadData之后和StationListElev = np.array(RawData['f3'])之后直接给你什么?
标签: python python-3.x colors scatter-plot