當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python Streamlit st.vega_lite_chart用法及代碼示例

使用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 序列化(即使用 config.dataFrameSerialization = "legacy" )不支持 Pyarrow 表。要使用 pyarrow 表,請通過更改配置設置啟用 pyarrow,config.dataFrameSerialization = "arrow"

spec (dict or None)

圖表的Vega-Lite 規範。如果規範已在前一個參數中傳遞,則必須將其設置為 None。有關詳細信息,請參閱https://vega.github.io/vega-lite/docs/

use_container_width (bool)

如果為 True,則將圖表寬度設置為列寬。這優先於Vega-Lite 的本機width 值。

**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 用法示例。其中大部分可以很容易地轉換為上麵顯示的語法。

相關用法


注:本文由純淨天空篩選整理自streamlit.io大神的英文原創作品 st.vega_lite_chart。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。