使用Vega-Lite 庫顯示圖表。
函數簽名
st.vega_lite_chart(data=None, spec=None, use_container_width=False, **kwargs)
參數 | 說明 |
---|---|
data (pandas.DataFrame, pandas.Styler, pyarrow.Table, numpy.ndarray, Iterable, dict, or None) | 要繪製的數據或包含數據的 Vega-Lite 規範(更接近於 Vega-Lite API)。 Streamlit 的舊版 DataFrame 序列化(即使用 |
spec (dict or None) | 圖表的Vega-Lite 規範。如果規範已在前一個參數中傳遞,則必須將其設置為 None。有關詳細信息,請參閱https://vega.github.io/vega-lite/docs/。 |
use_container_width (bool) | 如果為 True,則將圖表寬度設置為列寬。這優先於Vega-Lite 的本機 |
**kwargs (any) | 與規範相同,但作為關鍵字。 |
示例
import pandas as pd
import numpy as np
df = pd.DataFrame(
np.random.randn(200, 3),
columns=['a', 'b', 'c'])
st.vega_lite_chart(df, {
'mark': {'type': 'circle', 'tooltip': True},
'encoding': {
'x': {'field': 'a', 'type': 'quantitative'},
'y': {'field': 'b', 'type': 'quantitative'},
'size': {'field': 'c', 'type': 'quantitative'},
'color': {'field': 'c', 'type': 'quantitative'},
},
})
可以在 https://vega.github.io/vega-lite/examples/ 找到不使用 Streamlit 的 Vega-Lite 用法示例。其中大部分可以很容易地轉換為上麵顯示的語法。
相關用法
- Python Streamlit st.video用法及代碼示例
- Python Streamlit st.experimental_singleton.clear用法及代碼示例
- Python Streamlit st.bokeh_chart用法及代碼示例
- Python Streamlit st.caption用法及代碼示例
- Python Streamlit st.text_input用法及代碼示例
- Python Streamlit st.area_chart用法及代碼示例
- Python Streamlit st.title用法及代碼示例
- Python Streamlit st.cache用法及代碼示例
- Python Streamlit st.experimental_singleton用法及代碼示例
- Python Streamlit st.empty用法及代碼示例
- Python Streamlit st.error用法及代碼示例
- Python Streamlit st.slider用法及代碼示例
- Python Streamlit st.header用法及代碼示例
- Python Streamlit st.container用法及代碼示例
- Python Streamlit st.form_submit_button用法及代碼示例
- Python Streamlit st.form用法及代碼示例
- Python Streamlit st.plotly_chart用法及代碼示例
- Python Streamlit st.bar_chart用法及代碼示例
- Python Streamlit st.code用法及代碼示例
- Python Streamlit st.experimental_memo.clear用法及代碼示例
- Python Streamlit st.warning用法及代碼示例
- Python Streamlit st.image用法及代碼示例
- Python Streamlit st.markdown用法及代碼示例
- Python Streamlit st.expander用法及代碼示例
- Python Streamlit st.experimental_memo用法及代碼示例
注:本文由純淨天空篩選整理自streamlit.io大神的英文原創作品 st.vega_lite_chart。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。