Make Plotly graph Mobile Responsive in python

Viewed 534

I'm trying to make a Choropleth graph in plotly using python to be mobile responsive. I used meta viewport tag, and config responsive = True but the graph appear so small in the mobile screen. I want to make the graph flexible so it can take the width of the screen and replace the colorbar if needed when the screen is small.

the graph shows as here in mobile screen

the graph in mobile screen

the code generates this graph

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>")
0 Answers
Related