【发布时间】:2025-11-29 21:05:02
【问题描述】:
我正在构建有关全球疫苗接种率的等值线图。为了使用顺序颜色进行绘图,我使用Plotly 绘制地图,并使用streamlit 使用Python 在网页上渲染地图。但是地图太小了,我试过fig.update_layout()调整大小,但是地图没有居中。工具栏上的“全屏查看”正好解决了我的问题,因为它居中并且始终适合屏幕。那么,有没有办法让它全屏显示呢?
这是我的代码:
import streamlit as st
import pandas as pd
import plotly.express as px
vaccination_data = pd.read_csv('vaccinations.csv')
df = pd.DataFrame(vaccination_data)
def vaccination_lastest_date_by_country(df):
return df.groupby('location').last().reset_index()
country_lastest_vaccination = vaccination_lastest_date_by_country(df)
df_vaccination_by_country = country_lastest_vaccination.sort_values(by='total_vaccinations_per_hundred', ascending=True)
fig = px.choropleth(df_vaccination_by_country, locations="iso_code",
color="total_vaccinations_per_hundred",
hover_name="location",
color_continuous_scale=px.colors.sequential.Plasma) # should be able to adjust the color
fig.update_layout(autosize=False, width= 1200, height=800) # map not centered
st.plotly_chart(fig)
数据公开:https://github.com/owid/covid-19-data/blob/master/public/data/vaccinations/README.md
【问题讨论】:
-
试试
st.plotly_chart(fig,height=800)