matplotlib绘图(4)

本章我们主要学习的技能有:绘制饼图,填充区域。

1 绘制饼图

from pylab import *
figure(1,figsize=(6,6))

ax=axes([0.1,0.1,0.8,0.8])
labels=['Sping','Summer','Autumn','Winter']
explode=(0.02,0.1,0.1,0.2)
x=[15,30,45,10]
# explode爆炸 分裂 间隙  startangle 开始角度  默认从0开始,逆时针排列
pie(x,labels=labels,explode=explode,startangle=60,autopct='%1.1f%%')

show()

图片描述

2 填充区域

from matplotlib.pyplot import  *
import numpy as np

x=np.arange(0.0,2,0.01)

y1=np.sin(2*np.pi*x)
y2=1.2*np.sin(4*np.pi*x)

fig=figure()
ax=gca()

ax.plot(x,y1,color='black')
ax.plot(x,y2,color='black')
# 以X为定点选取Y值  where 条件   
ax.fill_between(x,y1,y2,where=y2>=y1,facecolors='darkblue',interpolate=True)
ax.fill_between(x,y1,y2,where=y2<=y1,facecolors='deeppink',interpolate=True)

ax.set_title('filled between')
show()

图片描述

评论

暂无评论