Visualize data in Snowflake Notebooks¶
In Snowflake Notebooks, you can use your favorite Python visualization libraries, such as matplotlib and plotly, to develop your visualizations.
本主题介绍如何使用以下库在笔记本中可视化数据:
数据集
The examples in this topic use the following toy dataset that is based on the Palmer’s Penguin dataset (https://allisonhorst.github.io/palmerpenguins/articles/intro.html).
| species | measurement | value |
|---|---|---|
| adeli | bill_length | 37.3 |
| adeli | flipper_length | 187.1 |
| adeli | bill_depth | 17.7 |
| chinstrap | bill_length | 46.6 |
| chinstrap | flipper_length | 191.7 |
| chinstrap | bill_depth | 17.6 |
| gentoo | bill_length | 45.5 |
| gentoo | flipper_length | 212.7 |
| gentoo | bill_depth | 14.2 |
您可以使用以下代码在笔记本中创建此数据集:
使用 Altair 可视化结果¶
Altair is imported by default on Snowflake Notebooks as part of Streamlit. Snowflake Notebooks currently support Altair version 4.0. For details on available visualization types when using Altair, see Vega-Altair: Declarative Visualization in Python (https://altair-viz.github.io/index.html).
The following code plots a stacked bar chart of all the measurements in a dataframe named df that contains the toy dataset:
运行单元格后,将显示以下可视化效果:

使用 matplotlib 可视化结果¶
要使用 matplotlib,请为您的笔记本安装 matplotlib 库:
- From the notebook, select Packages.
- Locate the matplotlib library and select the library to install it.
The following code plots the toy dataset, df, using matplotlib:
运行单元格后,将显示以下可视化效果:

For more details on using the st.pyplot chart element, see
st.pyplot (https://docs.streamlit.io/library/api-reference/charts/st.pyplot).
使用 plotly 可视化结果¶
要使用 plotly,请为您的笔记本安装 plotly 库:
- From the notebook, select Packages.
- Locate the plotly library and select the library to install it.
The following code plots a bar chart of the penguin measurements from the toy dataset, df:
运行单元格后,将显示以下可视化效果:

使用 seaborn 可视化结果¶
要使用 seaborn,您必须为您的笔记本安装 seaborn 库:
- From the notebook, select Packages.
- Locate the seaborn library and select the library to install it.
The following code plots a bar chart of the penguin measurements from the toy dataset, df:
运行单元格后,会显示以下可视化效果:

For more examples of seaborn visualizations, see the seaborn Example gallery (https://seaborn.pydata.org/examples/index.html).
使用 Streamlit 可视化结果¶
Streamlit is imported by default in Snowflake Notebooks. You can use chart elements supported by Streamlit version 1.39.0 to create a line chart, bar chart, area chart, or a map with points on it. See Chart elements (https://docs.streamlit.io/library/api-reference/charts) .
Note
Some Streamlit chart elements are not supported in Snowflake or might be subject to additional terms. See Streamlit support in notebooks.
To visualize the toy dataset, df, in a bar chart, you can use the following Python code:
运行两个单元格后,会显示以下可视化效果:

To learn more about how you can build interactive data apps with Streamlit, see Streamlit in notebooks.