pyplot.xlim
([xmin],[xmax]) >>>设置或返回x轴显示范围
pyplot.ylim
([ymin],[ymax]) >>>设置或返回y轴显示范围
pyplot.xlabel
(xlabel,fontdict = None,labelpad = None,** kwargs ) >>>设置x轴的标签
labelpad:标签与x轴的距离
text属性
pyplot.ylabel
(ylabel,fontdict = None,labelpad = None,** kwargs ) >>>设置x轴的标签
labelpad:标签与y轴的距离
text属性
pyplot.
grid
(b=None, which='major', axis='both', **kwargs) >>>配置网格线
b:是否显示网格线,如果该方法添加了任何参数,该属性默认为True
which:{'major','minor','both'}要应用的网格线
axis:{'both','x','y'}要应用的轴
linestyle:线条风格
color:线条颜色
linewidth:线条宽度
alpha:网格线透明度
pyplot.
axhline
(y=0, xmin=0, xmax=1, **kwargs) >>>绘制平行于X轴的水平线
y:水平线的y坐标
xmin:0表示从图最左边开始,介于0-1之间
xmax:1表示在图最右边结束,介于0-1之间
c:参考线的颜色
ls:参考线的线条风格
lw:参考线的线条宽度
lable:参考线文本标签
pyplot.
axvline
(x=0, ymin=0, ymax=1, **kwargs) >>>绘制平行于Y轴的水平线
x:水平线的x坐标
ymin:0表示从图最下边开始,介于0-1之间
ymax:1表示在图最上边结束,介于0-1之间
c:参考线的颜色
ls:参考线的线条风格
lw:参考线的线条宽度
lable:参考线文本标签
pyplot.
axvspan
(xmin, xmax,ymin=0, ymax=1, **kwargs) >>>绘制垂直于X轴的参考区域
xmin:参考区域x轴起点位置
xmax:参考区域x轴终点位置
ymin:0表示从图最下边开始,介于0-1之间
ymax:1表示在图最上边结束,介于0-1之间
pyplot.
axhspan
(ymin, ymax,xmin=0, xmax=1, **kwargs) >>>绘制垂直于Y轴的参考区域
ymin:参考区域y轴起点位置
ymax:参考区域y轴终点位置
xmin:0表示从图最左边开始,介于0-1之间
xmax:1表示在图最右边结束,介于0-1之间
pyplot.
annotate
(s,xy,* args,** kwargs ) >>>添加图形内容细节的指向形注释文本
s:注释文本
xy:要注释的点(x,y)
xytext:放置文本的位置(x,y)
color:注释文本颜色
weigth:注释文本的字体粗细风格
arrowprops:箭头的属性字典
'''
arrowstyle:箭头风格
'-' None
'->' head_length=0.4,head_width=0.2
'-[' widthB=1.0,lengthB=0.2,angleB=None
'|-|' widthA=1.0,widthB=1.0
'-|>' head_length=0.4,head_width=0.2
'<-' head_length=0.4,head_width=0.2
'<->' head_length=0.4,head_width=0.2
'<|-' head_length=0.4,head_width=0.2
'<|-|>' head_length=0.4,head_width=0.2
connectionstyle:连接风格
'angle' angleA=90, angleB=0, rad=0.0
'angle3' angleA=90, angleB=0
'arc' angleA=0, angleB=0, armA=None, armB=None, rad=0.0
'arc3' rad=0.0
'bar' armA=0.0, armB=0.0, fraction=0.3, angle=None
color:颜色
'''
bbox:文本所在框的样式,字典
'''
boxstyle:框的样式,round,square
ec:
fc:
'''
pyplot.
text
(x,y,s,fontdict = None,withdash = False,** kwargs ) >>>添加图形内容细节的无指向形注释文本
x:注释文本所在的横坐标
y:注释文本所在的纵坐标
s:注释文本
weight:注释文本内容的粗细风格
color:注释文本的字体颜色
rotation:顺时针旋转多少度
text属性
pyplot.
xticks
(ticks = None,labels = None,** kwargs ) >>>获取或设置当前刻度线位置和x轴标签
ticks:应该放置刻度的位置列表
labels:标签列表
text属性
pyplot.
yticks
(ticks = None,labels = None,** kwargs ) >>>获取或设置当前刻度线位置和y轴标签
ticks:应该放置刻度的位置列表
labels:标签列表
text属性
pyplot.
title
(label,fontdict = None,loc ='center',pad = None,** kwargs ) >>>设置图形内容的标题
label:标题文本
fontdict :控制标题文本外观的字典
'''
默认:
{'fontsize': rcParams['axes.titlesize'],
'fontweight' : rcParams['axes.titleweight'],
'verticalalignment': 'baseline',
'horizontalalignment': loc}
'''
loc : {'center','left','right'},str,optional 要设置的标题,默认为“中心”
pad:坐标与顶部轴的偏移量
text属性
pyplot.
legend
(* args,** kwargs ) >>>在轴上放置图例
handles:自定义内容
loc:位置;,str or int
bbox_to_anchor:图例定位(x,y),左上角的xy轴坐标
'''
'best' 0
'upper right' 1
'upper left' 2
'lower left' 3
'lower right' 4
'right' 5
'center left' 6
'center right' 7
'lower center' 8
'upper center' 9
'center' 10
'''
pyplot.
table
(** kwargs ) >>>向统计图形添加表格
cellText:表格的数值,按行分组,格式与DataFrame一致
cellColours:表格的数值的颜色,格式与cellText一致
cellLoc:表格中数据对齐方式,默认right, 可选left center
colWidths:表格每列的宽度,数组
rowLabels:行名
rowColours:行名所在单元格的颜色
rowLoc:行名对齐方式,默认left 可选right center
colLabels:列名
colColours:列名所在单元格的颜色
colLoc:列名对齐方式,默认center 可选right left
loc:位置,默认'bottom'
pyplot.
autoscale
(enable = True,axis ='both',tight = None ) >>>调整坐标轴范围
enable:是否开启自适应调整
axis:x,y,both
tight:是否将视图限制设置为数据限制
保存
pyplot.
savefig
(* args,** kwargs )
fname:文件路径
dpi:像素
解决中文乱码
plt.rcParams['font.sans-serif']=['SimHei'] # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False # 用来正常显示负号
text属性
Property | Description |
---|---|
agg_filter | a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array |
alpha | float |
animated | bool |
backgroundcolor | color |
bbox | dict with properties for patches.FancyBboxPatch |
clip_box | matplotlib.transforms.Bbox |
clip_on | bool |
clip_path | { (path.Path , transforms.Transform ), patches.Patch , None } |
color | color |
contains | callable |
figure | Figure |
fontfamily | {FONTNAME, 'serif', 'sans-serif', 'cursive', 'fantasy', 'monospace'} |
fontname | {FONTNAME, 'serif', 'sans-serif', 'cursive', 'fantasy', 'monospace'} |
fontproperties | font_manager.FontProperties |
fontsize | {size in points, 'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'} |
fontstretch | {a numeric value in range 0-1000, 'ultra-condensed', 'extra-condensed', 'condensed', 'semi-condensed', 'normal', 'semi-expanded', 'expanded', 'extra-expanded', 'ultra-expanded'} |
fontstyle | {'normal', 'italic', 'oblique'} |
fontvariant | {'normal', 'small-caps'} |
fontweight | {a numeric value in range 0-1000, 'ultralight', 'light', 'normal', 'regular', 'book', 'medium', 'roman', 'semibold', 'demibold', 'demi', 'bold', 'heavy', 'extra bold', 'black'} |
gid | str |
horizontalalignment | {'center', 'right', 'left'} |
in_layout | bool |
label | object |
linespacing | float (multiple of font size) |
multialignment | {'left', 'right', 'center'} |
path_effects | AbstractPathEffect |
picker | None or bool or float or callable |
position | (float, float) |
rasterized | bool or None |
rotation | {angle in degrees, 'vertical', 'horizontal'} |
rotation_mode | {None, 'default', 'anchor'} |
sketch_params | (scale: float, length: float, randomness: float) |
snap | bool or None |
text | string or object castable to string (but None becomes '' ) |
transform | Transform |
url | str |
usetex | bool or None |
verticalalignment | {'center', 'top', 'bottom', 'baseline', 'center_baseline'} |
visible | bool |
wrap | bool |
x | float |
y | float |
zorder | float |