【matplotlib】生成各种图表

一、场景

    工作中,可能需要使用脚本分析各种数据,并生成图表

 

二、工具

    matplotlib

    https://matplotlib.org/stable/install/index.html

 

三、安装

python -m pip install -U pip
python -m pip install -U matplotlib

 

 

四、生成图表

1、折线图

复制代码
import matplotlib.pyplot as plt
 
# 准备数据
x = [1, 2, 3, 4, 5]
y = [1, 4, 9, 16, 25]
 
# 创建折线图
plt.plot(x, y)
 
# 设置图表标题
plt.title('line example')
 
# 设置x轴和y轴标签
plt.xlabel('x')
plt.ylabel('y')
 
# 显示图表
plt.show()
复制代码

 图示

 

五、其他

1、UserWarning: FigureCanvasAgg is non-interactive, and thus cannot be shown plt.show()

IDE直接运行不行,需要在交互式窗口运行,打开terminal

$ python3 test.py

 

posted @   代码诠释的世界  阅读(107)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
历史上的今天:
2021-07-22 【mac】./gradlew: command not found错误处理
点击右上角即可分享
微信分享提示