- 您没有提供任何样本数据。我已包含苏格兰的 COVID 数据
- 你真的是在描述pandas cut 功能
- 已经用您定义的范围和颜色证明了这一点
df = pd.DataFrame({"areaCode": ["S12000034", "S12000006", "S12000047", "S12000017", "S12000018", "S12000020", "S12000013", "S12000023", "S12000026", "S12000027", "S12000030", "S12000041", "S12000035", "S12000014", "S12000039", "S12000033", "S12000045", "S12000021", "S12000029", "S12000040", "S12000036", "S12000005", "S12000042", "S12000008", "S12000010", "S12000011", "S12000049", "S12000019", "S12000050", "S12000048", "S12000038", "S12000028"],
"areaName": ["Aberdeenshire", "Dumfries and Galloway", "Fife", "Highland", "Inverclyde", "Moray", "Na h-Eileanan Siar", "Orkney Islands", "Scottish Borders", "Shetland Islands", "Stirling", "Angus", "Argyll and Bute", "Falkirk", "West Dunbartonshire", "Aberdeen City", "East Dunbartonshire", "North Ayrshire", "South Lanarkshire", "West Lothian", "City of Edinburgh", "Clackmannanshire", "Dundee City", "East Ayrshire", "East Lothian", "East Renfrewshire", "Glasgow City", "Midlothian", "North Lanarkshire", "Perth and Kinross", "Renfrewshire", "South Ayrshire"],
"long": [-2.79208, -4.02863, -2.98251, -4.66103, -4.75387, -3.20202, -6.65722, -2.90025, -2.85869, -1.37344, -4.32595, -2.8921, -5.22114, -3.83619, -4.52074, -2.20398, -4.22417, -4.7246, -3.83272, -3.60909, -3.27826, -3.75316, -2.97095, -4.29057, -2.72435, -4.3606, -4.21479, -3.11738, -3.9514, -3.88484, -4.56834, -4.72899],
"lat": [57.234692, 55.09621, 56.231121, 57.586571, 55.900299, 57.476799, 58.199379, 58.94334, 55.525951, 60.504951, 56.249531, 56.725182, 56.28944, 56.000751, 56.0014, 57.166969, 55.95829, 55.72789, 55.60453, 55.8992, 55.911201, 56.147839, 56.4776, 55.496738, 55.94207, 55.74868, 55.876492, 55.82111, 55.868141, 56.575279, 55.848621, 55.23008],
"newCasesByPublishDate": [8, 6, 20, 5, 4, 0, 1, 0, 5, 0, 5, 10, 7, 12, 5, 22, 15, 16, 39, 24, 140, 10, 41, 24, 28, 16, 117, 22, 54, 32, 44, 38],
"pop_total": [261210.0, 148860.0, 373550.0, 235830.0, 77800.0, 95820.0, 26720.0, 22270.0, 115510.0, 22920.0, 94210.0, 116200.0, 85870.0, 160890.0, 88930.0, 228670.0, 108640.0, 134740.0, 320530.0, 183100.0, 524930.0, 51540.0, 149320.0, 122010.0, 107090.0, 95530.0, 633120.0, 92460.0, 341370.0, 151950.0, 179100.0, 112610.0]})
fig = go.Figure(
go.Scattergeo(
lat=df["lat"],
lon=df["long"],
text=df["areaName"],
marker={
"color": pd.cut(
df["newCasesByPublishDate"],
bins=[0, 50, 70, 80, 100],
labels=["yellow", "green", "blue", "red"],
)
},
)
)
fig.update_layout(geo={"fitbounds": "locations"})