我有一个 Plotly Scattergeo 图形,它在 Dash 应用程序中只使用了大约 1/3 的屏幕。我试过明确设置情节的高度和宽度,但没有任何运气。似乎也没有任何导致此问题的 css。
灰色的 Scattergeo 更大,但被裁剪在似乎自动生成的剪辑组中。我不知道如何更改它的值。
如何让这个自动展开以使用整个纸张大小。下图显示纸张尺寸为蓝色)
生成此图像的代码:
# Create a scattergeo trace with square markers
trace = go.Scattergeo(
lat=plot['lat'],
lon=plot['lon'],
mode='markers+text',
marker=dict(
size=10,
color='blue',
opacity=0.7,
symbol='square'
),
text=plot['Callsign'],
textposition='middle right',
textfont=dict(size=8, color='white'),
hovertemplate="<b>%{text}</b><br>" +
"Tracknumber: %{customdata[0]}<br>" +
"Altitude: %{customdata[1]}<br>" +
"TAS: %{customdata[2]}<br>" +
"Date: %{customdata[3]}",
customdata=customdata
)
# Define the layout
layout = go.Layout(
geo=dict(
projection=dict(type='mercator', scale=33),
resolution=50,
center=dict(lat=frame["lat"], lon=frame["lon"]),
scope='europe',
bgcolor='black',
showcountries=True,
countrycolor='black',
landcolor='gray',
lakecolor='black',
),
coloraxis_showscale=False,
showlegend=False,
xaxis={"title": "", "showgrid": False, "zeroline": False, "visible": False },
yaxis={"title": "", "showgrid": False, "zeroline": False, "visible": False },
)
# Create the figure
fig = go.Figure(data=trace, layout=layout)
fig.update_layout(
paper_bgcolor="rgba(0,0,255,1)",
plot_bgcolor="rgba(255,0,0,0)",
margin={"r":0,"t":0,"l":0,"b":0, "autoexpand":True},
height=500
)
当我们设置
scope='europe'
时,投影似乎被(硬)裁剪了,我认为这是一个错误,因为通常我们应该能够定义我们自己的 lataxis/lonaxis 范围 无论范围如何,但是设置一个明确的在这种情况下,范围未被考虑在内,因为范围已设置:例如,“欧洲”范围产生狭窄的 clipPath,“北美”产生较窄的配合等,而文档说:
lataxis/lonaxis
- 设置此轴的范围(以度为单位),设置地图的 裁剪坐标。range
所以为了获得预期的布局/比例,保持范围不变并根据需要调整
center
、lataxis_range
和lonaxis_range
,然后调整投影scale
。
这里有一个产生“平方比”的例子:
layout = go.Layout(
geo=dict(
projection=dict(type='mercator', scale=1), # start with scale 1, then adjust
resolution=50,
center=dict(lat=frame["lat"], lon=frame["lon"]),
#scope='europe',
bgcolor='black',
showcountries=True,
countrycolor='black',
landcolor='gray',
lakecolor='black',
lataxis_range=[0, 90], # defines clip height
lonaxis_range=[-75, 105], # defines clip width
),
coloraxis_showscale=False,
showlegend=False,
xaxis={"title": "", "showgrid": False, "zeroline": False, "visible": False },
yaxis={"title": "", "showgrid": False, "zeroline": False, "visible": False },
)
或者,如果您需要“未剪辑”的地图,即。看起来像标准的“大/完整”矩形世界地图:
#...
lataxis_range=[-90, 90],
lonaxis_range=[-180, 180],