Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >Python应用开发——30天学习Streamlit Python包进行APP的构建(9)

Python应用开发——30天学习Streamlit Python包进行APP的构建(9)

作者头像
此星光明
发布于 2024-06-28 01:44:13
发布于 2024-06-28 01:44:13
23700
代码可运行
举报
运行总次数:0
代码可运行

st.area_chart

显示区域图。

这是围绕 st.altair_chart 的语法糖。主要区别在于该命令使用数据自身的列和指数来计算图表的 Altair 规格。因此,在许多 "只需绘制此图 "的情况下,该命令更易于使用,但可定制性较差。

如果 st.area_chart 无法正确猜测数据规格,请尝试使用 st.altair_chart 指定所需的图表。

Function signature[source]

st.area_chart(data=None, *, x=None, y=None, color=None, width=None, height=None, use_container_width=True)

Parameters

data (pandas.DataFrame, pandas.Styler, pyarrow.Table, numpy.ndarray, pyspark.sql.DataFrame, snowflake.snowpark.dataframe.DataFrame, snowflake.snowpark.table.Table, Iterable, or dict)

Data to be plotted.

x (str or None)

Column name to use for the x-axis. If None, uses the data index for the x-axis.

y (str, Sequence of str, or None)

Column name(s) to use for the y-axis. If a Sequence of strings, draws several series on the same chart by melting your wide-format table into a long-format table behind the scenes. If None, draws the data of all remaining columns as data series.

color (str, tuple, Sequence of str, Sequence of tuple, or None)

The color to use for different series in this chart. For an area chart with just 1 series, this can be: None, to use the default color. A hex string like "#ffaa00" or "#ffaa0088". An RGB or RGBA tuple with the red, green, blue, and alpha components specified as ints from 0 to 255 or floats from 0.0 to 1.0. For an area chart with multiple series, where the dataframe is in long format (that is, y is None or just one column), this can be: None, to use the default colors. The name of a column in the dataset. Data points will be grouped into series of the same color based on the value of this column. In addition, if the values in this column match one of the color formats above (hex string or color tuple), then that color will be used. For example: if the dataset has 1000 rows, but this column only contains the values "adult", "child", and "baby", then those 1000 datapoints will be grouped into three series whose colors will be automatically selected from the default palette. But, if for the same 1000-row dataset, this column contained the values "#ffaa00", "#f0f", "#0000ff", then then those 1000 datapoints would still be grouped into 3 series, but their colors would be "#ffaa00", "#f0f", "#0000ff" this time around. For an area chart with multiple series, where the dataframe is in wide format (that is, y is a Sequence of columns), this can be: None, to use the default colors. A list of string colors or color tuples to be used for each of the series in the chart. This list should have the same length as the number of y values (e.g. color=["#fd0", "#f0f", "#04f"] for three lines).

width (int or None)

Desired width of the chart expressed in pixels. If width is None (default), Streamlit sets the width of the chart to fit its contents according to the plotting library, up to the width of the parent container. If width is greater than the width of the parent container, Streamlit sets the chart width to match the width of the parent container.

height (int or None)

Desired height of the chart expressed in pixels. If height is None (default), Streamlit sets the height of the chart to fit its contents according to the plotting library.

use_container_width (bool)

Whether to override width with the width of the parent container. If use_container_width is False (default), Streamlit sets the chart's width according to width. If use_container_width is True, Streamlit sets the width of the chart to match the width of the parent container.

  • None, to use the default color.
  • A hex string like "#ffaa00" or "#ffaa0088".
  • An RGB or RGBA tuple with the red, green, blue, and alpha components specified as ints from 0 to 255 or floats from 0.0 to 1.0.

For an area chart with multiple series, where the dataframe is in long format (that is, y is None or just one column), this can be:

  • None, to use the default colors.
  • The name of a column in the dataset. Data points will be grouped into series of the same color based on the value of this column. In addition, if the values in this column match one of the color formats above (hex string or color tuple), then that color will be used. For example: if the dataset has 1000 rows, but this column only contains the values "adult", "child", and "baby", then those 1000 datapoints will be grouped into three series whose colors will be automatically selected from the default palette. But, if for the same 1000-row dataset, this column contained the values "#ffaa00", "#f0f", "#0000ff", then then those 1000 datapoints would still be grouped into 3 series, but their colors would be "#ffaa00", "#f0f", "#0000ff" this time around.

For an area chart with multiple series, where the dataframe is in wide format (that is, y is a Sequence of columns), this can be:

  • None, to use the default colors.
  • A list of string colors or color tuples to be used for each of the series in the chart. This list should have the same length as the number of y values (e.g. color=["#fd0", "#f0f", "#04f"] for three lines).

width (int or None) Desired width of the chart expressed in pixels. If width is None (default), Streamlit sets the width of the chart to fit its contents according to the plotting library, up to the width of the parent container. If width is greater than the width of the parent container, Streamlit sets the chart width to match the width of the parent container. height (int or None) Desired height of the chart expressed in pixels. If height is None (default), Streamlit sets the height of the chart to fit its contents according to the plotting library. use_container_width (bool) Whether to override width with the width of the parent container. If use_container_width is False (default), Streamlit sets the chart's width according to width. If use_container_width is True, Streamlit sets the width of the chart to match the width of the parent container.

代码

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
import streamlit as st
import pandas as pd
import numpy as np

chart_data = pd.DataFrame(np.random.randn(20, 3), columns=["a", "b", "c"])

st.area_chart(chart_data)

这段代码使用了Streamlit库来创建一个简单的Web应用程序。首先导入了streamlit、pandas和numpy库。然后创建了一个包含20行3列随机数的DataFrame,并命名为chart_data,列名分别为"a"、"b"和"c"。最后使用Streamlit的area_chart函数将chart_data作为参数,创建了一个面积图展示在Web应用程序上。

您还可以为 x 和 y 选择不同的列,以及根据第三列动态设置颜色(假设您的数据帧是长格式):

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
import streamlit as st
import pandas as pd
import numpy as np

chart_data = pd.DataFrame(
   {
       "col1": np.random.randn(20),
       "col2": np.random.randn(20),
       "col3": np.random.choice(["A", "B", "C"], 20),
   }
)

st.area_chart(chart_data, x="col1", y="col2", color="col3")

这段代码使用了Streamlit库来创建一个简单的数据可视化应用。首先导入了需要的库,包括streamlit、pandas和numpy。然后创建了一个包含随机数据的DataFrame对象chart_data,其中包括了三列数据:col1、col2和col3。接下来使用Streamlit的area_chart函数将这些数据可视化为一个面积图,其中x轴为col1,y轴为col2,颜色由col3决定。最终,这段代码将会在Streamlit应用中展示一个面积图,显示出col1和col2之间的关系,并用不同的颜色表示col3的取值。

最后,如果您的数据帧是宽格式,您可以在 y 参数下对多列进行分组,以不同的颜色显示多个序列:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
import streamlit as st
import pandas as pd
import numpy as np

chart_data = pd.DataFrame(np.random.randn(20, 3), columns=["col1", "col2", "col3"])

st.area_chart(
   chart_data, x="col1", y=["col2", "col3"], color=["#FF0000", "#0000FF"]  # Optional
)

这段代码使用Streamlit库创建了一个面积图。首先,它导入了streamlit、pandas和numpy库。然后,它使用numpy生成了一个包含随机数据的DataFrame,并将其命名为chart_data。随后,使用st.area_chart()函数创建了一个面积图,其中x轴使用"col1"列的数据,y轴使用"col2"和"col3"列的数据,同时可以选择性地指定颜色参数来设置面积图的颜色。

element.add_rows

将一个数据帧连接到当前数据帧的底部。

Function signature[source]

element.add_rows(data=None, **kwargs)

Parameters

data (pandas.DataFrame, pandas.Styler, pyarrow.Table, numpy.ndarray, pyspark.sql.DataFrame, snowflake.snow

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2024-06-28,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
Python应用开发——30天学习Streamlit Python包进行APP的构建(10)
它是 st.pydeck_chart 的包装器,用于在地图上快速创建散点图表,并具有自动居中和自动缩放功能。
此星光明
2024/06/28
3620
Python应用开发——30天学习Streamlit Python包进行APP的构建(10)
python︱写markdown一样写网页,代码快速生成web工具:streamlit 展示组件(三)
系列参考: python︱写markdown一样写网页,代码快速生成web工具:streamlit介绍(一) python︱写markdown一样写网页,代码快速生成web工具:streamlit 重要组件介绍(二) python︱写markdown一样写网页,代码快速生成web工具:streamlit 展示组件(三) python︱写markdown一样写网页,代码快速生成web工具:streamlit lay-out布局(四) python︱写markdown一样写网页,代码快速生成web工具:streamlit 缓存(五) python︱写markdown一样写网页,代码快速生成web工具:streamlit 数据探索案例(六) streamlit + opencv/YOLOv3 快速构建自己的图像目标检测demo网页(七)
悟乙己
2021/12/07
1.6K0
python︱写markdown一样写网页,代码快速生成web工具:streamlit 展示组件(三)
用Python制作数据大屏,超简单
今天我们用Streamlit模块来制作一个数据面板,将数据更加直观地呈现给别人观看,整个页面大致如下图所示
用户6888863
2022/04/13
2.1K0
用Python制作数据大屏,超简单
干货分享 | 用 Streamlit 来制作数据可视化面板教程(一)
对于数据分析师,建模工程师来说,将处理好的数据放在可视化的面板上进行呈现将更加有助于同事、领导来理解结果,今天小编就给大家来介绍一下如何用Python来制作一个数据可视化面板,使用的是Streamlit库,对于开发人员来说,只需几分钟就可以构建和部署强大的数据应用程序。
用户6888863
2021/07/19
3.8K0
python︱写markdown一样写网页,代码快速生成web工具:streamlit lay-out布局(四)
python︱写markdown一样写网页,代码快速生成web工具:streamlit介绍(一) python︱写markdown一样写网页,代码快速生成web工具:streamlit 重要组件介绍(二) python︱写markdown一样写网页,代码快速生成web工具:streamlit 展示组件(三) python︱写markdown一样写网页,代码快速生成web工具:streamlit lay-out布局(四) python︱写markdown一样写网页,代码快速生成web工具:streamlit 缓存(五) python︱写markdown一样写网页,代码快速生成web工具:streamlit 数据探索案例(六) streamlit + opencv/YOLOv3 快速构建自己的图像目标检测demo网页(七)
悟乙己
2021/12/07
1.5K0
python︱写markdown一样写网页,代码快速生成web工具:streamlit  lay-out布局(四)
不到100行Python代码教你做出精美炫酷的可视化大屏
“碳达峰、碳中和”是2021年政府在不断强调与非常重视的事儿,那什么是“碳达峰”、什么又是“碳中和”呢?这里小编来为大家科普一下,所谓的“碳达峰”指的是在某一时间点,二氧化碳的排放不再达到峰值,之后逐步回落。
用户6888863
2022/04/13
1.1K0
不到100行Python代码教你做出精美炫酷的可视化大屏
Python应用开发——30天学习Streamlit Python包进行APP的构建(12)
value (bool) Preselect the checkbox when it first renders. This will be cast to bool internally. key (str or int) An optional string or integer to use as the unique key for the widget. If this is omitted, a key will be generated for the widget based on its content. Multiple widgets of the same type may not share the same key. help (str) An optional tooltip that gets displayed next to the checkbox. on_change (callable) An optional callback invoked when this checkbox's value changes. args (tuple) An optional tuple of args to pass to the callback. kwargs (dict) An optional dict of kwargs to pass to the callback. disabled (bool) An optional boolean, which disables the checkbox if set to True. The default is False. label_visibility ("visible", "hidden", or "collapsed") The visibility of the label. If "hidden", the label doesn't show but there is still empty space for it (equivalent to label=""). If "collapsed", both the label and the space are removed. Default is "visible".
此星光明
2024/07/02
2810
Python应用开发——30天学习Streamlit Python包进行APP的构建(12)
Python应用开发——30天学习Streamlit Python包进行APP的构建(1)
现在你已经装好了 conda ,让我们来创建一个 conda 环境来管理所有 Python 库依赖。
此星光明
2024/05/31
6970
Python应用开发——30天学习Streamlit Python包进行APP的构建(1)
总结了67个pandas函数,完美解决数据处理,拿来即用!
不管是业务数据分析 ,还是数据建模。数据处理都是及其重要的一个步骤,它对于最终的结果来说,至关重要。
小F
2021/04/26
3.9K0
总结了67个pandas函数,完美解决数据处理,拿来即用!
用Streamlit构建机器学习应用
Streamlit是一个开放源码的Python库,它可以轻松地为机器学习建模漂亮的应用程序。你可以很容易地通过pip在你的终端上安装它,然后开始用Python编写你的网络应用程序。
AiTechYun
2019/11/11
1.3K0
用Streamlit构建机器学习应用
使用 Apache Hudi + Daft + Streamlit 构建 Lakehouse 分析应用
为了应对这些挑战,像 Streamlit[1] 这样的低代码工具作为 Python 生态系统的包装器,允许将 API、模型和业务逻辑变为现实。Streamlit 支持从数据库、API 和文件系统等各种来源轻松使用数据,从而轻松集成到应用程序中。在这篇博客中,我们将重点介绍如何使用直接来自开放湖仓一体平台的数据来构建数据应用。
ApacheHudi
2024/05/20
4370
使用 Apache Hudi + Daft + Streamlit 构建 Lakehouse 分析应用
Python 的一万种用法:制作 Web 可视化页面
本次小F给大家介绍一下如何用Python制作一个数据可视化网页,使用到的是Streamlit库,轻松将一个Excel数据文件转换为一个Web页面,提供给所有人在线查看。
AI科技大本营
2021/06/08
2.2K0
Python 的一万种用法:制作 Web 可视化页面
用Python制作销售数据可视化看板,展示分析一步到位!
主要使用Python的Streamlit库、Plotly库、Pandas库进行搭建。
小F
2021/11/23
2.4K0
Streamlit 入门教程:构建一个Dashboard
Streamlit 是一个用于创建数据科学和机器学习应用程序的开源 Python 库。它的主要目标是使开发人员能够以简单的方式快速构建交互式的数据应用,而无需过多的前端开发经验。Streamlit 提供了一种简单的方法来转换数据脚本或分析代码为具有可视化界面的应用程序,这些应用程序可以通过网络浏览器访问。
deephub
2023/08/30
1.4K0
Streamlit 入门教程:构建一个Dashboard
情人节,我用 Python 给女朋友做了个选礼物看板!
一年 N 度的情人节又又又到了!各位程序猿们给女朋友准备礼物了吗?刚铁直男都存在一个困惑的问题:送女朋友什么礼物好?今天特意爬取了某东的数据,来分析下大家情人节都送什么给女朋友。
杰哥的IT之旅
2022/03/31
7480
情人节,我用 Python 给女朋友做了个选礼物看板!
【干货原创】面向小白的最全Python可视化教程,超全的!
今天小编总结归纳了若干个常用的可视化图表,并且通过调用plotly、matplotlib、altair、bokeh和seaborn等模块来分别绘制这些常用的可视化图表,最后无论是绘制可视化的代码,还是会指出来的结果都会通过调用streamlit模块展示在一个可视化大屏,出来的效果如下图所示
用户6888863
2022/04/13
6510
【干货原创】面向小白的最全Python可视化教程,超全的!
用 Streamlit 做几个网页快捷小工具
在日常工作中,经常需要时间戳转化、base64 编码/解码等操作。之前一般通过搜索引擎搜索,可以找到相应工具的页面。现在有了 Streamlit ,可以快速制作出对应功能的网页应用。例如以下的一些例子
dandelion1990
2024/03/17
6580
Python应用开发——30天学习Streamlit Python包进行APP的构建(4)
创建 Streamlit 应用时要做的第一件事就是将 streamlit 库导入为 st,并且导入要用到的 requests 库:
此星光明
2024/05/31
6730
Python应用开发——30天学习Streamlit Python包进行APP的构建(4)
一日一技:Python快速生成web动态展示项目
一句话,Streamlit是一个可以用python编写web app的库,可以方便的动态展示你的机器学习的项目。
用户8949263
2022/04/08
1.4K0
一日一技:Python快速生成web动态展示项目
python︱写markdown一样写网页,代码快速生成web工具:streamlit介绍(一)
系列参考: python︱写markdown一样写网页,代码快速生成web工具:streamlit介绍(一) python︱写markdown一样写网页,代码快速生成web工具:streamlit 重要组件介绍(二) python︱写markdown一样写网页,代码快速生成web工具:streamlit 展示组件(三) python︱写markdown一样写网页,代码快速生成web工具:streamlit lay-out布局(四) python︱写markdown一样写网页,代码快速生成web工具:streamlit 缓存(五) python︱写markdown一样写网页,代码快速生成web工具:streamlit 数据探索案例(六) streamlit + opencv/YOLOv3 快速构建自己的图像目标检测demo网页(七)
悟乙己
2021/12/07
2.9K0
python︱写markdown一样写网页,代码快速生成web工具:streamlit介绍(一)
推荐阅读
相关推荐
Python应用开发——30天学习Streamlit Python包进行APP的构建(10)
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档