Day 2 用pyplot包进行函数式绘图
思想总览
用pyplot进行绘图是通过直接调用pyplot包当中的函数来实现,这种方式简单易上手,适合简单的绘图。调用pyplot中的函数进行绘图是在当前的figure 和 axes进行操作。
pyplot所有函数及其功能
函数 | 功能 |
---|---|
figure | 创建一个figure |
axis | 设置x和y轴的坐标范围 |
acorr | 绘制关于某个数据的自相关系数图 |
angle_spectrum | 绘制角度光谱 |
autoscale | 自动调整坐标范围和刻度与数据达到最适合的匹配效果 |
autumn | 把colormap设置为autumn模式 |
axes | 在当前的figure添加一个axes并把这个axes设置为当前的axes |
axhline | 在坐标区域添加一条水平直线 |
axhspan | 在坐标区域绘制一个矩形 |
bar | 绘制条形图 |
barbs | 绘制带倒钩的二维矢量场 |
barh | 绘制水平条形图 |
bone | 将colormap设置为bone |
box | 在当前axes开启或关闭箱线图模式 |
boxplot | 绘制箱线图 |
broken_barh | 绘制一系列的水平矩形 |
cla | 清除当前的axes |
clabel | 标记一个等高线图,就是对等高线进行标注 |
clf | 清除当前的figure |
clim | 设置当前图像的颜色范围 |
close | 关闭某个figure |
cohere | 绘制x和y之间的coherence |
colorbar | 在当前的绘图添加一个colorbar |
connect | 把某个函数和一个事件绑定起来,相当于Qt当中的信号与槽的机制 |
contour | 绘制等高线图——contour |
coutourf | 绘制等高线图 |
cool | 把colormap设置为cool模式 |
copper | 把colormap设置为copper模式 |
csd | 绘制一个cross-spectral density |
delaxes | 删除某个axes,默认为当前的axes |
disconnect | 不太懂,可能与connect相反 |
draw | 把当前的figure再画一次 |
errorbar | 绘制error bar |
eventplot | 绘制平行线 |
figimage | 在figure添加一个image |
figlegend | 在figure上放一个legend |
figtext | 在figure上放一个text |
fill | 绘制填充的多边形 |
fill_between | 填充两个水平曲线之间的区域 |
fill_betweenx | 填充两个垂直曲线的区域 |
flag | 把colormap设置成flag模式 |
gca | 获取当前的axes |
gcf | 获取当前的fig |
gci | 获得当前的colorable artist |
get | 获取某个object的所有的properties |
一系列get之类的函数 | 对于绘图来说不太重要 |
gray | 把colormap设置为gray模式 |
grid | 设置网格线 |
hexbin | 在点x,y作一个二维六边形图 |
hist | 画直方图 |
hist2D | 画一个二维直方图 |
hlines | 在每个y处从xmin到xmax画一条直线 |
hot | 把colormap设置为hot模式 |
hsv | 把colormap设置为hsv模式 |
imread | 把一张image读取为array |
imsave | 把一个array保存为image |
imshow | 把数据展示为二维图像 |
inferno | 把colormap设置为inferno模式 |
jet | 把colormap设置为jet模式 |
legend | 在axes放一个legend |
locator_params | 不知道什么用处 |
loglog | x和y都采用对数刻度进行绘图 |
magma | 把colormap调为magma模式 |
magnitude_spectrum | 绘制震级谱 |
margins | 不知道 |
matshow | 根据一个矩阵绘制图像 |
minorticks_off | 不知道 |
minorticks_on | 不知道 |
nipy_spectral | 把colormap设置为nipy_spectral模式 |
pcolor | 不知道 |
pcolormesh | 不知道 |
phase_spectrum | 绘制相位谱 |
pie | 绘制饼图 |
pink | colormap设置为pink |
plasma | colormap设置为plasma |
plot | 绘制折线图 |
polar | 绘制极坐标图 |
prism | 把colormap调为prism模式 |
psd | 绘制光谱功率密度 |
quiver | 绘制箭头表示的二维矢量场 |
quiverkey | 不知道,添加一个key到quiver绘图不知道什么意思 |
savefig | 保存当前的fig |
sca | 把当前的Axes保存 |
scatter | 绘制散点图 |
sci | set the current image不知道什么意思 |
semilogx | 绘制一张x采取对数刻度的图 |
semilogy | 绘制一张y采取对数刻度的图 |
set_cmap | 设置默认的colormap并应用 |
setp | 设置一个artist的property |
show | 显示figure |
specgram | 绘制一个光谱图 |
spring | colormap设置为spring模式 |
spy | 以图片的方式表示系数矩阵 |
stackplot | 绘制堆栈图 |
stem | 绘制棉棒图 |
step | 绘制阶梯图 |
streamplot | 画矢量流的流线 |
subplot | 对当前的figure添加一个subplot |
subplot2grid | 在某个特定的区域绘图 |
subplot_mosaic | 建立众多Axes的布局 |
subplot_tool | 弹出一个窗口,可视化地调整subplot的布局 |
subplots | 建立很多的subplots |
subplots_adjust | 调整subplot的布局的参数 |
summer | 把colormap设置为summer模式 |
suptitle | 在figure添加一个居中的标签 |
table | 在一个Axes中添加一个表格 |
text | 对Axes添加text |
thetagrids | 在当前极坐标绘图设置角网格 |
tick_params | 设置刻度的外观、标签等参数 |
ticklabel_format | 设置ticklabel的格式 |
tight_layout | 设置subplot之间的布局 |
title | 设置axes的标题 |
tricontour | 不知道 |
tricontourf | 不知道 |
tripcolor | 不知道 |
triplot | 不知道 |
twinx | Make and return a second axes that shares |
the x-axis. | |
twiny | Make and return a second axes that shares |
the y-axis | |
vlines | make a violin plot |
viridis | Set the colormap to “viridis” |
vlines | Plot vertical lines. |
winter | set the colormap to winter |
xcorr | 绘制x和y之间的cross correlation |
xlabel | 设置x-axis的标题 |
xlim | 设置x轴的范围 |
xticks | 设置x轴的刻度 |
xscale | 设置x轴的标度 |
ylabel | 设置y轴的标签 |
ylim | 设置y轴的范围 |
yscale | 设置y轴的标度 |
yticks | 设置y轴的刻度 |
title | 设置图标标题 |
legend | 设置图例 |
arrow | 在绘图区域添加箭头 |
常用函数详解
创建和设置figure
figure(num=None,figsize=None,dpi=None,facecolor=None,edgecolor=None,frameon=True, FigureClass=<class 'matplotlib.figure.Figure'>, clear=False, **kwargs)
Return:
一个Figure类的实例
Pramaters:
- num:int or string 图像的编号
- figsize:(float, float) 单位inches,表示图像的长*高,一英寸=2.5cm
- dpi:分辨率,即每英寸多少像素,默认为80,最高800
- facecolor:color, 默认为’White’,背景颜色
- edgecolor:color, 边框颜色
- frameon:bool, 是否显示边框,如果为false,就不显示边框
- -clear:bool, 如果为True且figure存在,就会把figure清理
- FigureClass:不知道,日后学习
- tight_layout:不知道,日后学习
- constrained_layout:不知道,日后学习
设置x和y轴的坐标范围
axis(*args, emit=True, **kwargs)
Return
:
元组:(xmin, xmax, ymin, ymax)
Parameters
传入一个列表就行了,[xmin, xmax, ymin, ymax]
其它参数实际用处不大