我正在使用纬度和经度绘制不同地点的地震位置。我使用 geojson 数据绘制地图,然后使用列名称“经度”和“纬度”在地图上绘制标记。但是标记和颜色条的颜色不一样,8.2 标记的圆圈应该比颜色条更暗红色,但在地图中却偏黄。怎么解决这个问题?
geojson_path = '/content/drive/MyDrive/ColabNotebooks/Practice/nepal.geojson'
gdf = gpd.read_file(geojson_path)
# Read CSV file using Pandas
mydata = pd.read_csv('/content/drive/MyDrive/ColabNotebooks/Practice/earthquakes.tsv', sep='\t')
df = mydata[mydata['Mag'].notnull()]
# Create a GeoDataFrame from the DataFrame with latitude and longitude
geometry = gpd.points_from_xy(df['Longitude'], df['Latitude'])
gdf_points = gpd.GeoDataFrame(df, geometry=geometry)
# Set up the subplots to take up the whole width
fig, ax = plt.subplots(figsize=(15, 8))
# Define a colormap and normalize values based on the 'Mag' column
cmap = plt.get_cmap('YlOrRd') # You can choose any other colormap
norm = Normalize(vmin=df['Mag'].min(), vmax=df['Mag'].max())
# Plot the GeoDataFrame with points, adjusting circle size based on the 'size' column
gdf.plot(ax=ax)
scatter = gdf_points.plot(
ax=ax,
cmap=cmap,
markersize=(df['Mag']) * 200,
c=df['Mag'], # Assign 'Mag' values as the color
norm=norm,
alpha=0.5
)
# Add colorbar for reference
sm = plt.cm.ScalarMappable(cmap=cmap, norm=norm)
sm.set_array([]) # You need to set an array to the ScalarMappable
cbar = plt.colorbar(sm, ax=ax, label='Magnitude')
# Annotate each point with its 'size' value
for x, y, label in zip(df['Longitude'], df['Latitude'], df['Mag']):
plt.text(x, y, str(label), color='white', ha='center', va='center')
plt.title('Map with Points from CSV')
plt.show()
您已设置
alpha=0.5
。 Alpha 是“透明度”的衡量标准;在您的情况下,标记颜色与背景蓝色混合 50%。
如果您希望标记具有与色阶匹配的纯色,请设置 alpha=1
。