我想画大量不同 colored颜色 的多边形.
使用add_shapes
会生成速度较慢的绘图.
我怀疑使用科洛普莱斯就足够好了.目前,我有以下代码:
import plotly.express as px
polygons = [[(1, 1), (1, 2), (2, 2), (2, 1), (1, 1)],
[(3, 3), (3, 4), (4, 4), (4, 3), (3, 3)],
[(5, 5), (5, 6), (6, 6), (6, 5), (5, 5)],
[(7, 7), (7, 8), (8, 8), (8, 7), (7, 7)]]
geojson = {'features': [], 'type': 'FeatureCollection'}
ids = []
for index, poly in enumerate(polygons):
temp_dict = {
'geometry': {
'coordinates': [polygons[index].copy()],
'type': 'Polygon'},
'type': 'Feature',
'id': index}
geojson['features'].append(temp_dict)
ids.append(index)
fig = px.choropleth(
geojson=geojson,
color=ids,
locations=ids)
fig.update_layout(margin={"r": 0, "t": 0, "l": 0, "b": 0})
fig.show()
这看起来很管用,但我想删除背景中的 map ,因为我的多边形与地理位置无关.有没有办法做到这一点,或者得到同等的结果?