当前位置:网站首页>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
边栏推荐
猜你喜欢

Cve-2019-0708 vulnerability exploitation of secondary vocational network security 2022 national competition

Chapter 120 SQL function round

Six practices of Windows operating system security attack and defense

Intuitive understanding entropy

Solution architect's small bag - 5 types of architecture diagrams

SQL Server 递归查询上下级

SQL Server 游标循环表数据

Windows installs redis and sets the redis service to start automatically

《Neo4j权威指南》简介,求伯君、周鸿袆、胡晓峰、周涛等大咖隆重推荐

精彩回顾 | DEEPNOVA x Iceberg Meetup Online《基于Iceberg打造实时数据湖》
随机推荐
206. Reverse linked list (linked list)
How can swagger2 custom parameter annotations not be displayed
最强日期正则表达式
Comparison and practice of prototype design of knowledge service app
colab
59、螺旋矩阵(数组)
MySQL common statements
Can Jerry's AES 256bit [chapter]
Read integrity monitoring techniques for vision navigation systems - 4 multiple faults in vision system
59. Spiral matrix (array)
Installing MySQL with CentOS / Linux
C#和数据库连接中类的问题
[Niuke challenge 47] C. conditions (BitSet acceleration Floyd)
Learning notes 7-depth neural network optimization
1. Sum of two numbers (hash table)
Comparison and practice of prototype design of knowledge service app
Net start MySQL MySQL service is starting MySQL service failed to start. The service did not report any errors.
VScode
SSH uses private key to connect to server without key
Wonderful review | deepnova x iceberg meetup online "building a real-time data Lake based on iceberg"