没有合适的资源?快使用搜索试试~ 我知道了~
首页Python Matplotlib实用操作汇总
Python Matplotlib实用操作汇总
需积分: 50 9 下载量 32 浏览量
更新于2023-04-28
评论
收藏 905KB PDF 举报
目前所包含的Matplotlib操作有如下:使用LaTex、解决中文和负号显示问题、生成数据、各字符含义、折线图、设置x, y 坐标范围及轴刻度、设置x, y 坐标标题、标题、插入文字及网格线、散点图、设置图例、文本框注释、箭头注释、水平线、垂直线及色带、移动坐标轴位置、柱形图、条形图、填充曲线、饼图、阶梯图、直方图、棉棒图、极坐标气泡图、极线图,后续会增加更多操作
资源详情
资源评论
资源推荐
🏖
Matplotlib实操1.0
前言
🌴
如果你需要此文档的原
👉
.ipynb
👈
文件,请联系我:
Email:z.q.feng@qq.com
如果此文档对你有帮助,请关注我的博客
😄
:
CSDN blog:https:blog.csdn.net/weixin_46584887?spm=1010.2135.3001.5343
人生苦短,我用Python
🏃🏃🏃
!
import this
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one and preferably only one obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea let's do more of those!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Author : Z.Q.Feng Matplotlib-Review-1.0
No. 1 / 32
📙
🏖
Matplotlib实操1.0
前言
🌴
📙
引入库
使用LaTex
解决中文和负号显示问题
生成数据
各字符含义
折线图
x, y 坐标范围及轴刻度
x, y 坐标标题、标题
插入文字及网格线
散点图
图例
文本框注释
箭头注释
水平线、垂直线及色带
移动坐标轴位置
柱形图
条形图
填充曲线
饼图
阶梯图
直方图
棉棒图
极坐标气泡图
极线图
引入库
使用LaTex
# 引入库
import numpy as np
import matplotlib.pyplot as plt
1
2
3
plt.rcParams['text.usetex'] = True1
Author : Z.Q.Feng Matplotlib-Review-1.0
No. 2 / 32
字符 Color 字符 LineStyle 字符 Marker 字符 Marker
b 蓝色 - 实线 p 五角点 v 倒三角形
g 绿色 -. 虚点线 h 六边形点 < 左三角形
r 红色 虚线 + 加号点 l vline
c 青色 : 点线 D 钻石 - hline
m 品红 d 瘦菱形点 ^ 上三角点
y 黄色 * 星形点 > 右三角点
k 黑色 s 正方点 . 点
w 白色 x 乘号点 o 圆点
解决中文和负号显示问题
生成数据
各字符含义
折线图
plt.rcParams['font.sans-serif'] = ['SimHei'] # 显示中文
plt.rcParams['axes.unicode_minus'] = False # 正常显示负号
1
2
# 生成数据,x 从 0 到 10, 30 个点
x = np.linspace(0, 10, 30)
y = np.sin(x)
1
2
3
plt.figure(figsize = (8, 6))
plt.plot(x, y,
color = 'r', # 颜色
marker = 'o', # 标记点型
ls = "", # 线型
lw = 2, # 线宽
label = "LinePlot" # 图例标签
)
plt.show()
1
2
3
4
5
6
7
8
9
Author : Z.Q.Feng Matplotlib-Review-1.0
No. 3 / 32
x, y 坐标范围及轴刻度
plt.figure(figsize = (8, 6))
plt.plot(x, y, label = "I'm legend")
# x坐标范围 (0,10), y 坐标范围 (-1.2, 1.2)
plt.xlim(0, 10)
plt.ylim(-1.2, 1.2)
# plt.axis([0, 10, -1.2, 1.2])
# 设定 x 轴刻度
plt.xticks([0, np.pi, 2 * np.pi, 3 * np.pi], # 原数值刻度
["0", r'$\pi$', r'2$\pi$', r'3$\pi$'], # 替换刻度
rotation = 90 # 旋转角度
)
# 设定 y 轴刻度
plt.yticks([-1, 0, 1], ['$-1$', '$0$', '$1$'],
fontsize = 'large' # 字体大小
)
plt.show()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Author : Z.Q.Feng Matplotlib-Review-1.0
No. 4 / 32
x, y 坐标标题、标题
plt.figure(figsize = (8, 6))
plt.plot(x, y)
# x, y 坐标标签
plt.xlabel('axis-x', fontsize = 15)
plt.ylabel('axis-y', fontsize = 15)
bbox_props = dict(boxstyle = 'square', # 方形文本框
fc = 'lightblue', # 背景颜色
ec = 'r', # 边框线条颜色
alpha = .9 # 透明度
)
plt.title("I'm title",
bbox = bbox_props, # 文本框样式
fontsize = 18, # 字体大小
fontweight = 'bold', # 字体粗细
rotation = 30, # 旋转角度
color = 'r', # 颜色
va = 'center', # 水平居中
ha = 'center' # 垂直居中
)
plt.show()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Author : Z.Q.Feng Matplotlib-Review-1.0
No. 5 / 32
剩余31页未读,继续阅读
Z.Q.Feng
- 粉丝: 783
- 资源: 20
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- zigbee-cluster-library-specification
- JSBSim Reference Manual
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0