如何使用cartopy在范围颜色中散布绘图值?

问题描述

我有这个df

     STATION LONGITUDE  LATITUDE  TMAXPERC
0    000130 -80.45750  -3.81333   9.034495
1    000132 -80.45722  -3.50833   7.291477
2    000134 -80.23722  -3.57611  15.760175
3    000135 -80.32194  -3.44056   5.256434
4    000136 -80.66083  -3.94889  12.301515
..      ...       ...       ...        ...
366  158323 -69.99972 -17.55917  57.318854
367  158325 -69.94889 -17.66083  87.762365
368  158326 -69.74556 -17.18639  40.719109
369  158327 -69.81306 -17.23722  86.950173
370  158328 -69.77944 -17.52500  53.413032

[371 rows x 4 columns]

我正在用这段代码制作一个带有纬度和经度的散点图。

import cartopy.crs as ccrs
import pandas as pd
import cartopy
%matplotlib inline
import numpy as np
import cartopy.io.img_tiles as cimgt
import cartopy.io.shapereader as shpreader
import cartopy.feature as cfeature
import matplotlib.pyplot as plt

data = pd.ExcelFile("path/filename.xlsx")
df =pd.read_excel(data,'Hoja1',dtype={'STATION': str})
df=df[['STATION','LONGITUDE','LATITUDE','TMAXPERC']]

reader = shpreader.Reader('C:/Ubuntu/Python/Shapefile/Dz/direcciones.shp')
counties = list(reader.geometries())
COUNTIES = cfeature.ShapelyFeature(counties,ccrs.PlateCarree())

plt.figure(figsize=(15,15))
stamen_terrain = cimgt.Stamen('terrain-background')
m10 = plt.axes(projection=stamen_terrain.crs)
plt.scatter(
    x=df["LONGITUDE"],y=df["LATITUDE"],color="red",s=4,alpha=1,transform=ccrs.PlateCarree()
)
# (x0,x1,y0,y1)
m10.set_extent([-85,-65,2,-20],ccrs.PlateCarree())         
# add map,zoom level
m10.add_image(stamen_terrain,8)
m10.add_feature(COUNTIES,facecolor='none',edgecolor='black')
m10.legend()
m10.gridlines()
plt.show()

结果如下:

enter image description here

但我想用 df['TMAXPERC']一个散点图。我想根据相应纬度和经度中的 TMAXPERC 值在地图中绘制带有 scalecolor 的点。我怎样才能做到这一点?提前致谢。

解决方法

您需要正确指定一些选项:

plt.scatter(
    x=df["LONGITUDE"],y=df["LATITUDE"],c=df["TMAXPERC"],cmap='viridis',#this is the changes
    s=4,alpha=1,transform=ccrs.PlateCarree()
)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...