如何在 streamlit 中的列内绘制图表

How can I plot graphs inside columns in streamlit

我试过下面的方法-

col1, col2, col3 = st.beta_columns(3)
col1.header = "confirmed"
col1.write("col1")
fig_con = alt.Chart(df).mark_line().encode(
  alt.X("days"),
  alt.Y("confirmed")
)
col1.st.altair_chart(fig_con)

col2.header = "recovered"
col2.write("col2")
fig_rec = alt.Chart(df).mark_line().encode(
  alt.X("days"),
  alt.Y("recovered")
)
col2.st.altair_chart(fig_rec)

col3.header = "deceased"
col3.write("col3")
fig_dec = alt.Chart(df).mark_line().encode(
  alt.X("days"),
  alt.Y("deceased")
)
col3.st.altair_chart(fig_dec)

但这似乎是错误的语法。

如果我这样做-

col1, col2, col3 = st.beta_columns(3)
col1.header = "confirmed"
col1.write("col1")
fig_con = alt.Chart(df).mark_line().encode(
  alt.X("days"),
  alt.Y("confirmed")
)
st.altair_chart(fig_con)

col2.header = "recovered"
col2.write("col2")
fig_rec = alt.Chart(df).mark_line().encode(
  alt.X("days"),
  alt.Y("recovered")
)
st.altair_chart(fig_rec)

col3.header = "deceased"
col3.write("col3")
fig_dec = alt.Chart(df).mark_line().encode(
  alt.X("days"),
  alt.Y("deceased")
)
st.altair_chart(fig_dec)

这将它们绘制在另一个下方。

这方面的文档有点缺乏,因为列功能处于测试阶段。

使用with col:

with col1:    
    col1.header = "confirmed"
    col1.write("col1")
    fig_con = alt.Chart(df).mark_line().encode(
      alt.X("days"),
      alt.Y("confirmed")
    )
    st.altair_chart(fig_con)
    
with col2:
    col2.header = "recovered"
    col2.write("col2")
    fig_rec = alt.Chart(df).mark_line().encode(
      alt.X("days"),
      alt.Y("recovered")
    )
    st.altair_chart(fig_rec)

with col3:
    col3.header = "deceased"
    col3.write("col3")
    fig_dec = alt.Chart(df).mark_line().encode(
      alt.X("days"),
      alt.Y("deceased")
    )
    st.altair_chart(fig_dec)