Python使用matplotlib填充图形指定区域代码示例
作者:Python_小屋 时间:2022-10-16 10:30:12
本文代码重点在于演示Python扩展库matplotlib.pyplot中fill_between()函数的用法。
import numpy as np
import matplotlib.pyplot as plt
# 生成模拟数据
x = np.arange(0.0, 4.0*np.pi, 0.01)
y = np.sin(x)
# 绘制正弦曲线
plt.plot(x, y)
# 绘制基准水平直线
plt.plot((x.min(),x.max()), (0,0))
# 设置坐标轴标签
plt.xlabel('x')
plt.ylabel('y')
# 填充指定区域
plt.fill_between(x,y, where=(2.3<x) & (x<4.3) | (x>10), facecolor='purple')
# 可以填充多次
plt.fill_between(x,y,where=(7<x) & (x<8), facecolor='green')
plt.show()
演示效果:
来源:http://blog.csdn.net/oh5W6HinUg43JvRhhB/article/details/78138919
标签:python,matplotlib,填充颜色
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python判断一个变量是否已经设置的方法
2022-06-09 19:33:15
Python基于xlrd模块操作Excel的方法示例
2021-07-18 16:04:06
Android App端与PHP Web端的简单数据交互实现示例
2023-07-02 08:16:16
![](https://img.aspxhome.com/file/2023/6/138356_0s.png)
PHP ob缓存以及ob函数原理实例解析
2023-11-18 17:36:14
layui table 表格上添加日期控件的两种方法
2024-02-25 10:05:14
Python下使用Trackbar实现绘图板
2023-12-11 10:13:04
![](https://img.aspxhome.com/file/2023/3/102863_0s.png)
Python中常见的加密解密算法总结
2021-10-18 12:13:17
linux系统使用python监控apache服务器进程脚本分享
2021-10-15 00:15:41
Python实现文本特征提取的方法详解
2023-05-09 05:09:19
![](https://img.aspxhome.com/file/2023/4/112954_0s.png)
python设置表格边框的具体方法
2023-11-13 08:08:48
![](https://img.aspxhome.com/file/2023/9/107099_0s.jpg)
Javascript将string类型转换int类型
2023-09-17 00:05:37
Python编写带选项的命令行程序方法
2023-11-18 20:47:35
Python Merge函数原理及用法解析
2021-10-02 00:16:11
![](https://img.aspxhome.com/file/2023/3/95183_0s.jpg)
Python OpenCV的基本使用及相关函数
2022-11-16 11:24:55
![](https://img.aspxhome.com/file/2023/9/68819_0s.jpg)
详细解读Python的web.py框架下的application.py模块
2021-06-24 22:28:47
pyinstaller参数介绍以及总结详解
2023-12-02 11:11:59
![](https://img.aspxhome.com/file/2023/0/112840_0s.png)
利用Python自动生成PPT的示例详解
2021-10-16 18:25:08
![](https://img.aspxhome.com/file/2023/6/111856_0s.jpg)
JavaScript Reduce使用详解
2024-04-19 10:16:03
![](https://img.aspxhome.com/file/2023/0/135870_0s.jpg)
教你用Python matplotlib库制作简单的动画
2021-08-20 02:58:49
![](https://img.aspxhome.com/file/2023/2/77622_0s.gif)
python合并RepeatMasker预测结果中染色体的overlap区域
2021-12-28 21:29:35
![](https://img.aspxhome.com/file/2023/7/127867_0s.jpg)