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

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.

代码

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 选择不同的列,以及根据第三列动态设置颜色(假设您的数据帧是长格式): 

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 参数下对多列进行分组,以不同的颜色显示多个序列:

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/739769.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

llama系列模型学习

一、目录 llama1 模型与transformer decoder的区别llama2 模型架构llama2 相比llama1 不同之处llama3 相比llama2 不同之处llama、llama2、llama3 分词器词表大小以及优缺点采用的损失函数是什么?为什么Layer Norm 改为RMS Norm?如何消除模型幻觉? 二…

Mac电脑FTP客户端推荐:Transmit 5 for Mac 中文版

Transmit 5是一款专为macOS平台设计的功能强大的FTP(文件传输协议)客户端软件。Transmit 5凭借其强大的功能、直观易用的界面和高效的性能,成为需要频繁进行文件传输和管理的个人用户和专业用户的理想选择。无论是对于新手还是经验丰富的用户…

KT6368A芯片使用后出现扫描不到蓝牙,2脚持续高电平串口没有反应

KT6368A蓝牙芯片连接问题 问题描述: 蓝牙芯片使用一段时间后,出现扫描不到蓝牙(部分芯片出现,出现概率挺高),更换新的芯片后就可以扫描到蓝牙 上电后检测2引脚(下图BLE_LINK引脚)…

使用vant4+vue3制作电商购物网站

一、前言 1.本项目基于vant4vue3构建,默认友友们已具备相关知识,如不具备,请友友们先去了解相关该概念 2.项目数据来源于开源框架 新峰商城 在此指出 3.此项目目的在于帮助友友们了解基本的用法,没有涉及太多的逻辑操作。 二、…

宝塔面板一键迁移项目站点教程

此插件仅用于将当前机器数据迁移出去,数据接收机器无需安装此插件。 注意事项: 当前教程仅适用《宝塔一键迁移API版本》插件,版本号 >3.0。 推荐迁移面板版本 > 6.9.5,低版本迁移可能存在部分数据无法迁移成功。 面板版…

Future You:对话未来的自己

是由麻省理工开发的 AI 聊天机器人,通过填写一系列表单和上传自己的照片,即可看到老年后的自己并与之对话。

怎么将图片压缩调小?在线压缩图片的4种快捷方法

压缩图片是日常很常用的一个图片处理功能,现在拍摄和制作的图片都比较大,在使用时经常会受到影响。在遇到无法上传、传输过慢的问题时会降低工作效率,所以掌握一招快速压缩图片是非常重要的。通过下面这篇文章来给大家介绍一下在线图片压缩的…

193.回溯算法:组合总和(力扣)

代码解决 class Solution { public:vector<int> res; // 当前组合的临时存储vector<vector<int>> result; // 存储所有符合条件的组合// 回溯函数void backtrcing(vector<int>& nums, int target, int flag, int index) {// 如果当前组合的和超过了…

预备役二招算法测试题解

这次题目出的都是一些偏向于基础的题目&#xff0c;就是一些简单的模拟&#xff0c;思维&#xff0c;以及基础算法&#xff08;二分&#xff0c;前缀和&#xff09; &#xff08;点击题目标题&#xff0c;进入原题&#xff09; 我是签到题 题解&#xff1a;就是说给你 t 组数据…

【MDK5问题】:MDK中的jlink正常下载,但是板子却没有任何反应

1、问题现象&#xff1a; 1、在MDK5中&#xff0c;jlink配置项如下图&#xff0c;没有看到异常情况和配置&#xff1a; 2、点击load下载到板子上&#xff0c;出现的现象是&#xff0c;下载提示下载完成&#xff0c;但是&#xff0c;板子却没有任何反应&#xff08;程序实现应该…

音频傅里叶变换(基于开源kissffs)

主要参考资料&#xff1a; 深入浅出的讲解傅里叶变换&#xff08;真正的通俗易懂&#xff09;: https://zhuanlan.zhihu.com/p/19763358 推荐开源项目&#xff1a;KISS FFT&#xff1a; https://blog.csdn.net/gitblog_00031/article/details/138840117 数字硅麦数据的处理&…

【Linux】基础IO_1

文章目录 六、基础IO1. C语言的文件接口2. 系统文件I/O 未完待续 六、基础IO 1. C语言的文件接口 我们知道 文件 文件内容 文件属性 。即使是一个空文件&#xff0c;仍然会在磁盘中占据空间。那打开文件是什么意思呢&#xff1f;其实文件打开的意思就是&#xff1a;将文件从…

上海舆情分析软件的功能和对企业的意义

随着互联网的飞速发展&#xff0c;人们参与讨论、发声的途径与评率也越来越多&#xff0c;在为自己发声的同时&#xff0c;公众舆论也成为企业获取民意&#xff0c;改进发展的重要参考。 上海 舆情分析软件的开发&#xff0c;为企业获取舆论&#xff0c;调查研究提供了便捷化的…

探寻Scala的魅力:大数据开发语言的入门指南

大数据开发语言Scala入门 一、引言1.1 概念介绍1.2 Scala作为大数据开发语言的优势和应用场景1.2.1 强大的函数式编程支持1.2.2 可与Java无缝集成1.2.3 高性能和可扩展性1.2.4 大数据生态系统的支持 二、Scala基础知识2.1. Scala简介&#xff1a;2.1.1 Scala的起源和背景2.1.2 …

【Win】USB设备连接与移除的实时追踪

在这个信息爆炸的时代&#xff0c;USB设备成了我们不可或缺的数据伴侣。但你有没有想过&#xff0c;当你的USB突然消失&#xff0c;或者你不确定它何时被拔出&#xff0c;这可能会让你陷入困境。别担心&#xff0c;即使Windows系统没有默认提供监控功能&#xff0c;我们也可以轻…

fairseq (Facebook AI Research) 包

0. Abstract 最近在看一个用 RNNs 网络做 Translation 任务的程序, 关于数据处理部分, 主要用到工具包 sentencepiece 和 fairseq, 前者主要是对文本进行分词处理, 后者则是对已分词的文本进行二进制化和快速加载. 包越方便使用, 就说明包装得越狠, 也就越令人一头雾水, 本文简…

巧用newSingleThreadExecutor让异步任务顺序跑

背景 Flume 是 Cloudera 提供的一个高可用的&#xff0c;高可靠的&#xff0c;分布式的海量日志采集、聚合和传输的系统 。一个用来控制 Flume 采集任务的 Web 应用&#xff0c;需要对任务进行管理&#xff0c;主要操作「启动、停止、新建、编辑、删除」&#xff0c;本质就是对…

神经网络实战2-损失函数和反向传播

其实就是通过求偏导的方式&#xff0c;求出各个权重大小 loss函数是找最小值的&#xff0c;要求导&#xff0c;在计算机里面计算导数是倒着来的&#xff0c;所以叫反向传播。 import torch from torch.nn import L1Lossinputstorch.tensor([1,2,3],dtypetorch.float32) targe…

品牌策划背后的秘密:我为何对此工作情有独钟?

你是否曾有过一个梦想&#xff0c;一份热爱&#xff0c;让你毫不犹豫地投身于一个行业&#xff1f; 我就是这样一个对品牌策划充满热情的人。 从选择职业到现在&#xff0c;我一直在广告行业里“混迹”&#xff0c;一路走来&#xff0c;也见证了许多对品牌策划一知半解的求职…

RubyMine 2024 mac/win版:智慧编程,从心出发

JetBrains RubyMine 2024 是一款专为Ruby和Rails开发者打造的高效集成开发环境(IDE)。它凭借其卓越的性能和丰富的功能&#xff0c;帮助开发者在Ruby和Rails的开发过程中提升效率&#xff0c;减少错误。 RubyMine 2024 mac/win版获取 RubyMine 2024 提供了强大的代码编辑功能&…