当前位置: 首页 > news >正文

【Pandas】pandas Series plot.line

Pandas2.2 Series

Plotting

方法描述
Series.plot([kind, ax, figsize, …])用于绘制 Series 对象的数据可视化图表
Series.plot.area([x, y, stacked])用于绘制堆叠面积图(Stacked Area Plot)
Series.plot.bar([x, y])用于绘制垂直条形图(Vertical Bar Plot)
Series.plot.barh([x, y])用于绘制水平条形图(Horizontal Bar Plot)
Series.plot.box([by])用于绘制箱线图(Box Plot)
Series.plot.density([bw_method, ind])用于绘制核密度估计图(Kernel Density Estimate Plot)
Series.plot.hist([by, bins])用于绘制直方图(Histogram)
Series.plot.kde([bw_method, ind])用于绘制核密度估计图(Kernel Density Estimate Plot)
Series.plot.line([x, y])用于绘制折线图(Line Plot)

pandas.Series.plot.line([x, y])

pandas.Series.plot.line 方法用于绘制折线图(Line Plot)。折线图可以展示数据随某个变量的变化趋势,特别适用于时间序列数据。

参数说明
  • x:可选,Series 的索引或列名,作为 x 轴的数据。
  • y:可选,Series 的列名,作为 y 轴的数据。
示例
import pandas as pd
import matplotlib.pyplot as plt

plt.rcParams['font.family'] = ['SimHei']

# 创建一个示例 Series
data = pd.Series([10, 20, 30, 40, 50], index=[1, 2, 3, 4, 5])

# 绘制折线图
data.plot(kind='line', title='折线图示例', color='blue', marker='o')
plt.xlabel('索引')
plt.ylabel('值')
plt.show()

# 创建一个示例 DataFrame 用于多系列折线图
data_multi = pd.DataFrame({
    'A': [10, 20, 30, 40, 50],
    'B': [5, 15, 25, 35, 45]
}, index=[1, 2, 3, 4, 5])

# 绘制多系列折线图
data_multi.plot(kind='line', title='多系列折线图示例', color=['blue', 'green'], marker='o')
plt.xlabel('索引')
plt.ylabel('值')
plt.show()
结果
  1. 折线图示例

    • 图表类型:折线图
    • 标题:折线图示例
    • 数据系列:示例 Series
    • x 轴:索引
    • y 轴:值
    • 图线颜色:蓝色
    • 数据点标记:圆圈
    • 显示内容:数据随索引的变化趋势
  2. 多系列折线图示例

    • 图表类型:折线图
    • 标题:多系列折线图示例
    • 数据系列:A 和 B
    • x 轴:索引
    • y 轴:值
    • 图线颜色:蓝色和绿色
    • 数据点标记:圆圈
    • 显示内容:多个系列随索引的变化趋势

通过这些示例,可以看到 pandas.Series.plot.line 方法如何绘制单个 Series 和多系列的折线图,从而直观地展示数据的变化趋势。折线图特别适用于时间序列数据和其他连续数据的分析。

相关文章:

  • TCP netstat TIME_WAIT CLOSE_WAIT
  • 利用dify打造命令行助手
  • 基于SpringBoot + Vue 的垃圾分类管理系统
  • Qt信号与槽机制入门详解:从基础语法到界面交互实战
  • 测试用例组成及设计方法
  • Zotero·Awesome GPT配置
  • 基于CentOS系统搭建Samba服务
  • 提高库存周转率的重要性
  • 风格混合增强的解纠缠学习在医学图像分割的无监督域自适应中的应用|文献速递-医学影像人工智能进展
  • 【USTC 计算机网络】第三章:传输层 - 可靠数据传输的原理
  • MAC terminal
  • 2025-3-23 leetcode刷题情况(动态规划)
  • 不能解析域名怎么回事?
  • 游戏引擎学习第180天
  • SQL中体会多对多
  • C++11中智能指针的使用(shared_ptr、unique_ptr、weak_ptr)
  • FPGA_YOLO(三)
  • Python使用SVC算法解决乳腺癌数据集分类问题——寻找最佳核函数
  • 【UEFI】关于Secure Boot
  • 2.3.5 覆盖率数据的合并
  • 印度宣布即日起对所有巴基斯坦航班关闭领空
  • 普京与卢卡申科举行会晤,将扩大在飞机制造等领域合作
  • 北京银行一季度净赚超76亿降逾2%,不良贷款率微降
  • 五一“拼假”催热超长假期,热门酒店民宿一房难求
  • 打造沪派水乡的“湿意”,上海正在保护营造一批湿地空间
  • 中国银行副行长刘进任该行党委副书记