Python-Matplotlib 22 填充区域

Python-Matplotlib 22 填充区域

 

1 概念
  对曲线下面或者曲线之间的区域进行填充
  fill, fill_between

 

 

EG1

import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure()

ax1 = fig.add_subplot(211)
x = np.linspace(0 ,5 * np.pi , 100)

y1 = np.sin(x)
y2 = np.sin(2*x)

ax1.fill(x, y1 , 'b' , alpha=0.3)
ax1.fill(x, y2, 'r' , alpha=0.3)

ax2  = fig.add_subplot(212)
ax2.fill_between(x, y1 , y2 , where=y1 > y2, facecolor='y' , interpolate=True) # 空白处插入颜色
ax2.fill_between(x, y1 , y2 , where=y1 < y2, facecolor='b' ,interpolate=True)

plt.show()

 

 

  

posted @ 2017-02-22 13:48  ZSR0401  阅读(4047)  评论(0)    收藏  举报