matplotlib.markers的样式
markers样式
条形图/柱状图
matplotlib.pyplot.bar()
直方图
统计数组出现的数量
直方图是对连续变量进行统计的图表,函数为matplotlib.pyplot.hist()
x 输入值
bins 表示绘制条柱的个数
range bins的上下范围(最大值和最小值
color 条柱的颜色
alpha 表示透明度 接收0-1的小数点。
散点图
虽然plot通过改变maker来进行画散点图,but !!!
这里有一个更专业的函数来进行画散点图的使用。
matplotlib.pyplot.scatter()
堆叠图
matplotlib.pyplot.stackplot
堆叠图一般用来显示各部分随时间变化的比重的变化.
import matplotlib.pyplot as plt
time = ['19/01', '19/02', '19/03', '19/04', '19/05']
eat = [0.6, 0.5, 0.7, 0.9, 0.8]
game = [0.2, 0.2, 0.1, 0.0, 0.1]
shopping = [0.1, 0.2, 0.1, 0.1, 0.1]
travel = [0.1, 0.1, 0.1, 0.0, 0.0]
plt.figure(figsize = (10, 7))
plt.stackplot(time, [eat, game, shopping, travel], labels = ['吃', '游戏', '购物', '旅游']) # 这里不把yi放到[]里也是可以的
plt.legend()
plt.title('消费占比')
plt.show()
饼图
函数为matplotlib.pyplot.pie(),更多内容查阅pie。部分参数如下
案例:
from matplotlib import pyplot
pyplot.rcParams['font.sans-serif']=['SimHei']
pyplot.rcParams['axes.unicode_minus'] = False
pyplot.figure()
family1=[2,5,12,70,2,9]
family2=[5,1,60,56,12,8]
color=['b','g','r','y','c','m']
labels=['娱乐','育儿','饮食','房贷','交通','其他']
pyplot.pie(family1,colors=color,autopct='%1.1f%%',pctdistance=0.85)
pyplot.pie([1],colors='w',radius=0.74)
pyplot.pie(family2,colors=color,radius=0.7,autopct='%1.1f%%',pctdistance=0.85)
pyplot.pie([2],colors='w',radius=0.4)
pyplot.title("饼图示例-8月份两个家庭支出")
pyplot.legend(labels=labels,bbox_to_anchor=(1.1,1.05),title="简表")
pyplot.show()
更多的函数 请参考 文档:
文档