matplotlib基础函数函数 plot, figure

本文详细介绍了Matplotlib库中plt.plot和plt.figure函数的使用方法,包括如何通过fmt参数快速设置线条样式,以及如何利用关键字参数进行更精细的控制。同时,文章还解释了如何通过scalex和scaley参数调整坐标轴的缩放比例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

matplotlib.pyplot.plot(*args, scalex=True, scaley=True,data=None,**kwargs)

用线段和标记去绘制x和y。调用签名:

plot([x], y, [fmt], *, data=None, **kwargs)
plot([x], y, [fmt], [x2], y2, [fmt2], ..., **kwargs)

点或线的坐标由x, y给出

操作参数 fmt 是为了方便设置基础格式: color, marker and linestyle

,是一种快捷的字符表示法

plot(x, y)      		# 绘制 x 和 y 通过默认的线段和颜色
plot(x, y, 'bo') 	 # 绘制x  和 y 使用蓝圆圈标志
plot(y)      #绘制y , x 使用数组 0.......N-1
plot(y, 'r+') # 同上, 使用红色加号

你可以使用二维线段 配置 作为关键参数来控制更多地显示,线面两行代码展示同样的效果:

plot(x, y, 'go--', linewidth=2, markersize=12)
plot(x, y, color='green', marker='o', linestyle='dashed',linewidth=2, markersize=12)

可以绘制多个数据集

plot(x1, y1, 'bo')
plot(x2, y2, 'go')

参数介绍:

x, y 类数组 或者 标量
通常为一维数组
关键参数不能省
fmt 字符, 操作符 (可选)
线段格式, 颜色格式 ‘ro’
只是快捷地设置属性, 可以用keywords 参数替换

fmt = ‘[marker][line][color]’

data 可选
returns: lines
Other Parameters : scalex, scaley: 可选
**kwargs: 二维线段 可选

matplotlib.pyplot.figure(num=None, figsize=None, dpi=None, facecolor=None, edgecolor=None, frameon=True, FigureClass=, clear=False, *kwargs)

parameters :

num: 整型或者字符串, 可选, 默认:None

如果没有提供, 自动创建一个, 如果提供了, 如果这个id的已经存在, 则激活这个figure, 返回一个引用, 如果不存在就创建一个,如果是一个字符串, 会当成这个figure 的title,

figsize:(float, float),可选, unit 英寸, 默认[6.4, 4.8]

dpi: integer, 可选, default:None, 默认 :100.0
facecolor: 背景色, 默认‘white’
edgecolor: border color
frameon: bool, 可选, default: True,
如果False , 禁止绘制
FigureClass: subclass of Figure
clear: bool, optional, default:False
如果是True, 如果figure已经存在, 则清空

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值