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()

 

 

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM