当前位置:网站首页>Solutions to common problems in visualization (IX) background color
Solutions to common problems in visualization (IX) background color
2022-04-23 10:54:00 【The big pig of the little pig family】
Background color problem
One . Preface
In the process of data visualization , We usually encounter the problem of changing the color of Beijing , Today, let's study together in matploltlib The color of one canvas in the changes .
Two . Solution

matplotlib A canvas is made up of a figure and axes form .
2.1 change figure Color
every last Figure Objects all have one patch attribute , Store his Beijing Rectangle object , Get Association Rectangle Use after object set_color() Method to set the background color .
import matplotlib.pyplot as plt
figure, ax = plt.subplots(1, 1)
patch = figure.patch
patch.set_color("red")
plt.show()
Change effect :

2.2 change axes The background color
Empathy , every last Axes Objects are also associated with a Rectangle object , Use the same method to change the background color . The code is as follows :
import matplotlib.pyplot as plt
import numpy as np
figure, ax = plt.subplots(1, 1)
patch = ax.patch
patch.set_color("blue")
plt.show()
The effect is as follows :

2.3 Advanced - The background uses a gradient
The background color can not only use solid color, but also use gradient color , The principle that it implements is to use imshow Method to draw a gradient background on the background , And modify his transparency , So you can draw on the gradient background . However, it should be noted that if the background transparency is too large, it will have a great impact on the actual drawing .
import matplotlib.pyplot as plt
import numpy as np
figure, ax = plt.subplots(1, 1)
patch = ax.patch
patch.set_color("blue")
x = np.arange(200)
y = np.arange(200)
_, yv = np.meshgrid(x, y)
im = ax.imshow(yv, interpolation='bicubic',cmap="PuOr",
vmin=0, vmax=200, alpha=0.5)
plt.plot([1, 100], [30, 150], color='k')
plt.show()
The effect is as follows :

3、 ... and . Reference resources
版权声明
本文为[The big pig of the little pig family]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230617063449.html
边栏推荐
- 二叉树的构建和遍历
- 链表相交(链表)
- MapReduce core and foundation demo
- Windows installs redis and sets the redis service to start automatically
- Image processing - Noise notes
- Pycharm
- A diary of dishes | 238 Product of arrays other than itself
- 【leetcode】102. Sequence traversal of binary tree
- 19、删除链表的倒数第N个节点(链表)
- ID number verification system based on visual structure - Raspberry implementation
猜你喜欢

比深度学习更值得信赖的模型ART

【leetcode】102. Sequence traversal of binary tree

解决方案架构师的小锦囊 - 架构图的 5 种类型

Introduction to wechat applet, development history, advantages of applet, application account, development tools, initial knowledge of wxml file and wxss file

Chapter 120 SQL function round

Jinglianwen technology - professional data annotation company and intelligent data annotation platform

Intuitive understanding entropy

mysql同一个表中相同数据怎么合并

Deploy jar package

Learning note 5 - gradient explosion and gradient disappearance (k-fold cross verification)
随机推荐
Esp32 learning - use and configuration of GPIO
任意文件读取漏洞 利用指南
精彩回顾 | DEEPNOVA x Iceberg Meetup Online《基于Iceberg打造实时数据湖》
解决方案架构师的小锦囊 - 架构图的 5 种类型
mysql同一个表中相同数据怎么合并
/etc/shadow可以破解吗?
SQL Server 递归查询上下级
SQL Server cursor circular table data
Detailed explanation of MapReduce calculation process
CentOS/Linux安装MySQL
Charles function introduction and use tutorial
997、有序数组的平方(数组)
206. Reverse linked list (linked list)
【leetcode】102. Sequence traversal of binary tree
部署jar包
MySQL common statements
定义链表(链表)
349. Intersection of two arrays
Diary of dishes | Blue Bridge Cup - hexadecimal to octal (hand torn version) with hexadecimal conversion notes
Define linked list (linked list)