根据.csv单单元格值更改.shp多边形颜色

问题描述 投票:0回答:1

我有一个 pyplot,其中三个 .shp 多边形作为子块。我想根据 3 列和 2 行的 .csv 文件(标题和值)中的值更改每个多边形的颜色。我想让每个多边形通过 2 个阈值。例如,>5= 黄色,>10= 红色,否则蓝色。我打算自动化 .csv,以便多边形根据 .csv 文件中的值更改颜色。我尝试过条件参数,但没有任何效果。

import geopandas as gpd
import matplotlib.pyplot as plt
import pandas as pd
import csv


gdf1 = gpd.read_file("FDRA_1.shp")
gdf2 = gpd.read_file("FDRA_2.shp")
gdf3 = gpd.read_file("FDRA_3.shp")`

row = 2; col = 1
with open("Valley_Index.csv") as f:
    reader = csv.reader(f)
    for i in range(row):
        row = next(reader)
    VIndex = row[col - 1]
threshold1=5


fig, ax = plt.subplots()

 for i in VIndex:
    color = 'coral' if VIndex > threshold1 else 'blue'
    ax.fill(x, y, color=color)

gdf1.plot(ax=ax, color='blue', edgecolor='black')


gdf2.plot(ax=ax, color='red', edgecolor='black')


gdf3.plot(ax=ax, color='green', edgecolor='black')


plt.title('Multiple Polygons')
plt.xlabel('Longitude')
plt.ylabel('Latitude')


plt.show()
python if-statement polygon geopandas threshold
1个回答
0
投票

我正在尝试使用 .csv 文件(3 列,2 行)中的值在 pyplot 中为多边形着色。我想为每个多边形设置颜色阈值(例如,>5 = 黄色,>10 = 红色,否则为蓝色) .我尝试过使用条件语句,但无法让它发挥作用,有什么建议吗?

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.