问题描述
我有一个正在使用Dashly Dash制作的仪表板,我想增加显示地图的Choropleth窗口的大小而不增加图形的大小。我要摆脱的地图区域上方和下方有一堆空白,如下图所示。
**注意:在图像中,我放大了地图以清楚显示地图窗口边界。
增加图形大小不会消除此空白。我的边距设置为0。
如何扩大地图区域的大小?
这是该图的代码:
import pandas as pd
import plotly.express as px
dff = df.copy()
with urlopen('https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json') as response:
counties_json = json.load(response)
fips = pd.read_csv("https://data.ny.gov/api/views/79vr-2kdi/rows.csv?accesstype=DOWNLOAD&sorting=true",usecols=["County Name","County FIPS"],dtype={"fips": str})
fips=fips.drop_duplicates(subset="County Name")
#fips=fips[["County Name","County FIPS"]]
fips["County Name"] = fips["County Name"].str.replace("St LaWrence","St. LaWrence")
fips.loc[fips["County Name"]=="St. LaWrence","County FIPS"] = 36089
m = dff.groupby("COUNTY_NAME")["ACC_ID"].count().reset_index()
m = m[~(m["COUNTY_NAME"]=="UnkNown") & ~(m["COUNTY_NAME"]=="Out-Of-State")]
m = m.set_index('COUNTY_NAME').join(fips.set_index('County Name'))
m = m.reset_index()
data = pd.DataFrame.from_dict(data)
#data=pd.read_json(cleanj_data,orient='split')
data = data.groupby("COUNTY_NAME")["ACC_ID"].count().reset_index()
data = data[~(data["COUNTY_NAME"]=="UnkNown") & ~(data["COUNTY_NAME"]=="Out-Of-State")]
m = pd.merge(m,data,how="left",on="COUNTY_NAME")
m["ACC_ID_y"] = m["ACC_ID_y"].fillna(0)
fig = px.choropleth(m,geojson=counties_json,locations='County FIPS',color='ACC_ID_y',color_continuous_scale="blues",scope="usa",labels={'Name':'COUNTY_NAME',"ACC_ID_y":"Number of Samples"},hover_name="COUNTY_NAME",hover_data={"County FIPS":False,"ACC_ID_y":True},center={"lat":43.049543,"lon":-76.149094},)
fig.add_scattergeo(geojson=counties_json,locations=m['County FIPS'],text=m["COUNTY_NAME"],mode='text',textfont=dict(size=8,color="black"),textposition="bottom center",hoverinfo="skip")
fig.update_geos(showcountries=False,showcoastlines=False,showland=False,fitbounds="locations",visible=False)
fig.update_layout(width=850,height=600,margin={"r":0,"t":0,"l":0,"b":0},hoverlabel=dict(bgcolor=px.colors.sequential.Blues[8]))
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)