在 Python 中的 csv 文件中绘制带有经纬度和填充值的网格化地图
plot gridded map with lat-lon and fill values in csv file in Python
1我有一个 .csv
文件包含几列:lon, lat, var1, var2 ...
df = pd.read_csv('D:/file.csv')
gdf = gpd.GeoDataFrame(df)
Lon = df['lon']
Lat = df['lat']
Slope = df['slope']
编辑:如何在上面的 table (lon, lat, slope) 上绘制我的数据具有 lon (-179.5 degree to 179.5 degree), lat (-89.5 to 89.5 degree)
和 1 度空间分辨率的全球网格地图。
[]
import numpy as np
import cartopy
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
import pandas as pd
import random
latz = np.linspace(-89.5, 89.5, 180)
lonz = np.linspace(-0.5, 359.5, 361)
x, y = np.meshgrid(lonz, latz)
rand_list = [random.randrange(1, 5, 1) for i in range(64980)]
# you probably need to sort your df by lat/long and
# you'll want to replace rand_list with:
#z = np.array_split(df['slope'].values.tolist(), 180)
z = np.array_split(rand_list, 180)
fig = plt.figure(figsize=[16, 16])
ax = plt.subplot(1, 1, 1, projection=ccrs.PlateCarree())
ax.set_extent([-179.5, 180, -89.5, 90], crs=ccrs.PlateCarree())
ax.add_feature(cfeature.LAND, zorder=1, facecolor='0.25')
ax.add_feature(cartopy.feature.OCEAN, zorder=4)
ax.pcolormesh(x, y, z, transform=ccrs.PlateCarree(), zorder=3)
plt.show()
1我有一个 .csv
文件包含几列:lon, lat, var1, var2 ...
df = pd.read_csv('D:/file.csv')
gdf = gpd.GeoDataFrame(df)
Lon = df['lon']
Lat = df['lat']
Slope = df['slope']
编辑:如何在上面的 table (lon, lat, slope) 上绘制我的数据具有 lon (-179.5 degree to 179.5 degree), lat (-89.5 to 89.5 degree)
和 1 度空间分辨率的全球网格地图。
import numpy as np
import cartopy
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
import pandas as pd
import random
latz = np.linspace(-89.5, 89.5, 180)
lonz = np.linspace(-0.5, 359.5, 361)
x, y = np.meshgrid(lonz, latz)
rand_list = [random.randrange(1, 5, 1) for i in range(64980)]
# you probably need to sort your df by lat/long and
# you'll want to replace rand_list with:
#z = np.array_split(df['slope'].values.tolist(), 180)
z = np.array_split(rand_list, 180)
fig = plt.figure(figsize=[16, 16])
ax = plt.subplot(1, 1, 1, projection=ccrs.PlateCarree())
ax.set_extent([-179.5, 180, -89.5, 90], crs=ccrs.PlateCarree())
ax.add_feature(cfeature.LAND, zorder=1, facecolor='0.25')
ax.add_feature(cartopy.feature.OCEAN, zorder=4)
ax.pcolormesh(x, y, z, transform=ccrs.PlateCarree(), zorder=3)
plt.show()