python - 在 python 中制作 Plotly 图形移动响应
问题描述
我正在尝试使用 python 制作一个 Choropleth 图,以实现移动响应。我使用了元视口标签,并且 config responsive = True 但图表在移动屏幕上显得如此之小。我想让图形变得灵活,这样它就可以占据屏幕的宽度,并在屏幕较小时根据需要替换颜色条。
该图在移动屏幕中显示为here
代码生成此图
data = [go.Choropleth(
colorscale = scl,
autocolorscale = False,
locations = us_map['code'],
z = us_map['stat_main'].astype(float),
zmin = 0,
zmax = 100,
locationmode = 'country names',
text = us_map['text'],
hovertemplate = '%{text}',
marker = go.choropleth.Marker(
line = go.choropleth.marker.Line(
color = 'rgb(255,255,255)',
width = 2
)),
colorbar = go.choropleth.ColorBar(
title = "Recovery Index"))]
layout = go.Layout(
title = go.layout.Title(
text = "Some html text", x=0, xanchor='left', y=0.95, yanchor='top'
),
#width=1000,
#height=600,
geo = go.layout.Geo(
scope = 'world',
projection = go.layout.geo.Projection(type = 'natural earth'),
showlakes = True,
lakecolor = 'rgb(255, 255, 255)'),)
fig1 = go.Figure(data = data, layout = layout)
fig1.update_layout(coloraxis_colorbar=dict(
thicknessmode="pixels", thickness=50,
lenmode="pixels", len=200,
yanchor="top", y=1,
ticks="outside", ticksuffix=" bills",
dtick=5))
combined_html = open('State_Graphs/country_graphs.html', 'w')
combined_html.write("<html><head><meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.2, minimum-scale=0.5'><link rel='stylesheet' href='https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css' integrity='sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z' crossorigin='anonymous'></head><body> <div class='container'>")
add_js = True
combined_html.write("<div class='row'><div class='col-12' >")
inner_html = plotly.offline.plot(
fig1, include_plotlyjs=add_js, output_type='div',
config={'modeBarButtonsToRemove': ['toImage','pan2d', 'lasso2d', 'select2d','autoScale2d','toggleSpikelines',],
'displaylogo': False,
'scrollZoom': True,
'responsive':True,
'displayModeBar': False}
)
combined_html.write(inner_html)
combined_html.write("</div> </div>")
解决方案
推荐阅读
- .net-core - 该请求缺少身份验证密钥。请参阅 IHttpClientFactory 的“身份验证”部分
- html - Uncaught Invariant Violation:对象作为 React 子对象无效(发现:[object HTMLInputElement])
- swift - 元组数据到 Swift 键值对。它是一个 python 对象,响应是单引号字符串
- r - 根据条件计算跨行的值
- postgresql - 使用 ALTER TABLE 动态添加新列的功能
- serverless-framework - 我可以将整个 node_modules 文件夹部署为 lambda 层吗?
- html - 让渐变穿过两个并排的 Divs React
- python - 如何在python中解释余弦相似度输出
- javascript - 使用 express.js 我收到此错误:未捕获的错误 [ERR_HTTP_HEADERS_SENT]:在将标头发送到客户端后无法设置标头
- stdstring - main.cpp:10:17:错误:预期表达式