其他分享
首页 > 其他分享> > matplotlib常用函数总结

matplotlib常用函数总结

作者:互联网

matplotlib是python数据可视化的基础包。当前能搜到的博客所列举的内容都太少,很难满足定制化需求

 官方文档:https://matplotlib.org/stable/api/pyplot_summary.html

首先调用接口

import matplotlib pyplot as plt

 

下面除了直接绘制图表的函数以外每一个函数都是可选的,如果不需要定制该部分内容,可以不写。

 

首先整个图就是一个figure对象

pyplot.figure(figsize=None, dpi=None, facecolor=None, edgecolor=None, frameon=True, clear=False)

 

然后设置标题

plt.title(label, fontdict=None, loc=None, pad=None)

 

设置X轴和Y轴的标题

plt.xlabel(xlabel, fontdict  = None , labelpad  = None , loc  = None )

 

设置坐标轴的范围,也就是每个轴上的最大最小值。

1 # 使用axis()
2 plt.axis([xmin,xmax,ymin,ymax])
3 # 或者xlim()/ylim()
4 plt.xlim(left,right)

 

设置坐标轴的刻度

1 # 在刻度为0,1,2的位置显示标签'January', 'February', 'March',并把标签旋转20°
2 plt.xticks([0, 1, 2], ['January', 'February', 'March'], rotation=20)  # Set text labels and properties.

 

设置坐标轴方向上的网格线

1 plt.grid(visible=None, which='major', axis='both', color='r', linestyle='-', linewidth=2)

 

图例

https://zhuanlan.zhihu.com/p/111108841

 

常见图表类型的绘图函数

 

折线图

1 plt.plot(x, y)

 

散点图

1 plt.scatter(x, y)

 

柱形图

1 plt.bar(x, height)

 

条形图

1 plt.barh(x, height

 

其他图

# 面积图
plt.fill_between(x, y1, y2)
# 饼图
plt.pie(x)
# 统计直方图
plt.hist(x)
# 箱型图
plt.boxplot(x)
# 误差棒
plt.errorbar(x, y)

 

标签:总结,None,plt,函数,matplotlib,边框,散点,默认,标题
来源: https://www.cnblogs.com/andoblog/p/16123505.html