使用 GeoPandas 创建头部图并且重新调整的图像很小 - 如何更改比例?
Using GeoPandas to create a head map and the retuned image is tiny - how to change the scale?
我正在尝试创建美国的热图,输出似乎很好,只是轴比例比需要的大得多,导致输出图像很小。
这是源数据的问题还是我可以解决的问题?
我的代码:
states = 'USAstates.shp'
map_usa = gpd.read_file(states)
merged = map_usa.set_index('STUSPS').join(statecount.set_index('state'))
merged.head()
# set a variable that will call whatever column we want to visualise on the map
variable = 'index'
# create figure and axes for Matplotlib
fig, ax = plt.subplots(1, figsize=(10, 6))
lims = plt.axis('equal')
merged.plot(column=variable, cmap='Blues', linewidth=0.8, ax=ax, edgecolor='0.8')
和输出:
我试过更改 figsize 输入,但这并没有多大帮助。
有人可以建议我应该如何正确缩放吗?
谢谢!
绘图的最右侧有一些几何图形。如果您只想缩放到美国大陆,您可以删除该几何图形或将 xlim
设置为轴。
fig, ax = plt.subplots(1, figsize=(10, 6))
merged.plot(column=variable, cmap='Blues', linewidth=0.8, ax=ax, edgecolor='0.8')
ax.set_xlim(-180, -50) # just a guess here
我正在尝试创建美国的热图,输出似乎很好,只是轴比例比需要的大得多,导致输出图像很小。
这是源数据的问题还是我可以解决的问题?
我的代码:
states = 'USAstates.shp'
map_usa = gpd.read_file(states)
merged = map_usa.set_index('STUSPS').join(statecount.set_index('state'))
merged.head()
# set a variable that will call whatever column we want to visualise on the map
variable = 'index'
# create figure and axes for Matplotlib
fig, ax = plt.subplots(1, figsize=(10, 6))
lims = plt.axis('equal')
merged.plot(column=variable, cmap='Blues', linewidth=0.8, ax=ax, edgecolor='0.8')
和输出:
我试过更改 figsize 输入,但这并没有多大帮助。 有人可以建议我应该如何正确缩放吗?
谢谢!
绘图的最右侧有一些几何图形。如果您只想缩放到美国大陆,您可以删除该几何图形或将 xlim
设置为轴。
fig, ax = plt.subplots(1, figsize=(10, 6))
merged.plot(column=variable, cmap='Blues', linewidth=0.8, ax=ax, edgecolor='0.8')
ax.set_xlim(-180, -50) # just a guess here