Python的matplotlib绘图如何修改背景颜色的实现
作者:wangdan113269 时间:2023-10-05 08:12:43
在主图中背景颜色不知道怎么改,plt.plot()中没有axisbg参数。
但是子图可以对plt.subplot的参数做修改,下面是对子图的背景颜色修改代码
import matplotlib.pyplot as plt
import numpy as np
# Fixing random state for reproducibility
np.random.seed(19680801)
dt = 0.01
t = np.arange(0, 30, dt)
nse1 = np.random.randn(len(t)) # white noise 1
nse2 = np.random.randn(len(t)) # white noise 2
s1 = np.sin(2 * np.pi * 10 * t) + nse1
s2 = np.sin(2 * np.pi * 10 * t) + nse2
s3 = np.sin(2 * np.pi * 10 * t) + nse1
s4 = np.sin(2 * np.pi * 10 * t) + nse2
fig= plt.figure(1) # 创建图表1
axs0=plt.subplot(221,axisbg='#FFDAB9') #在图标1中创建子图
axs0.plot(t, s1) #横轴与纵轴数据
axs0.set_xlim(0, 2) #限制x轴的取值范围
axs1=plt.subplot(222,axisbg='#7FFF00')
axs1.plot(t, s2)
axs1.set_xlim(0, 2)
axs2=plt.subplot(223,axisbg='#FF7F50')
axs2.plot(t, s3)
axs2.set_xlim(0, 2)
axs3=plt.subplot(224,axisbg='#A9A9A9')
axs3.plot(t, s4)
axs3.set_xlim(0, 2)
plt.show()
来源:https://blog.csdn.net/wangdan113269/article/details/82888148
标签:Python,matplotlib,背景颜色
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
分享PHP函数实现数字与文字分页代码
2023-11-14 12:32:54
Kali Linux 2022.1安装和相关配置教程(图文详解)
2023-11-10 15:54:50
![](https://img.aspxhome.com/file/2023/5/99365_0s.jpg)
vue组件三大核心概念图文详解
2024-05-09 15:22:42
![](https://img.aspxhome.com/file/2023/5/126435_0s.png)
python基于twisted框架编写简单聊天室
2021-12-12 17:56:51
![](https://img.aspxhome.com/file/2023/2/76822_0s.jpg)
Bootstrap显示与隐藏简单实现代码
2023-08-24 17:30:54
![](https://img.aspxhome.com/file/2023/1/56221_0s.jpg)
python字符串切片及常用方法示例详解
2021-01-02 15:40:20
vue 使用饿了么UI仿写teambition的筛选功能
2024-04-27 16:05:09
![](https://img.aspxhome.com/file/2023/3/133013_0s.gif)
Python常用字符串替换函数strip、replace及sub用法示例
2022-04-07 18:21:17
SQL Server数据库连接查询的种类及其应用
2009-01-06 11:28:00
表单设计中的网页视觉体验
2008-06-26 13:35:00
![](https://img.aspxhome.com/file/UploadPic/20086/26/2008626134221567s.jpg)
JSP + Servlet实现生成登录验证码示例
2023-06-27 02:47:59
![](https://img.aspxhome.com/file/2023/9/56249_0s.png)
Python Requests安装与简单运用
2023-09-26 22:02:15
使用python itchat包爬取微信好友头像形成矩形头像集的方法
2021-02-01 17:54:10
![](https://img.aspxhome.com/file/2023/7/131267_0s.jpg)
json显示日期带T问题的解决方法
2022-05-12 16:50:37
Python导出DBF文件到Excel的方法
2023-03-12 20:50:15
win10+RTX3050ti+TensorFlow+cudn+cudnn配置深度学习环境的方法
2023-02-12 14:02:00
![](https://img.aspxhome.com/file/2023/1/132291_0s.png)
8行代码实现Python文件去重
2023-11-20 14:47:35
![](https://img.aspxhome.com/file/2023/4/64334_0s.jpg)
微软Silverlight技术魅力初体验
2008-11-05 11:16:00
![](https://img.aspxhome.com/file/uploadpic/200811/5/47fe8a0e93ec22f6ab6457e1-97.jpg)
让css使网页图片半透明
2007-02-03 11:39:00
![](https://img.aspxhome.com/file/uploadpic/20072/200723113958642.jpg)
大写锁定提醒
2009-06-11 13:12:00
![](https://img.aspxhome.com/file/UploadPic/20096/11/win2003_capslk-48s.png)