当前位置:网站首页>Visual Road (XII) detailed explanation of collection class
Visual Road (XII) detailed explanation of collection class
2022-04-23 10:54:00 【The big pig of the little pig family】
The road to Visualization ( Twelve )Collection Class explanation
One . brief introduction
Collection
Class draws classes that share a large collection of objects that share most properties , Is the base class for all collection classes . He can't use it alone , You must subclass before you can use .
Two . Class definition
def __init__(self,
edgecolors=None,
facecolors=None,
linewidths=None,
linestyles='solid',
capstyle=None,
joinstyle=None,
antialiaseds=None,
offsets=None,
transOffset=None,
norm=None, # optional for ScalarMappable
cmap=None, # ditto
pickradius=5.0,
hatch=None,
urls=None,
offset_position='screen',
zorder=1,
**kwargs
):
Parameters 1:edgecolors: Specifies the color of the edge of the color block .
Parameters 2:facecolors: Specifies the color of the color patch .
Parameters 3:linewidths: Specifies the color block lineweight .
Parameters 4:linestyles: Specifies the color block linetype .
Parameters 5:capstyle: Specifies the line brush style .
Parameters 6:joinstyle: Specify the connection style .
Parameters 7:antialiaseds: Boolean type , Specifies whether each object in the collection should be anti aliased painted .
Parameters 8:offset: Specifies the color block offset .
Parameters 9:norm: Specifies whether to normalize .
Parameters 10:cmap: Appoint colormap.
Parameters 11:pickradius: Specifies the pick radius for tightness testing .
Parameters 12:hatch: Specifies the internal hatch pattern .
Parameters 13:urls: Unknown ?
Parameters 14:offset_position: Specifies that the offset is treated as data coordinates rather than screen coordinates .
Parameters 15:zoeder: Specifies the color patch layer .
Parameters 16:**kwargs: The received keyword parameters are passed to Artist
Base class .
Yes Collection Instances of its subclasses , Use get_ The attribute name ()
Get the corresponding property value of the current instance .
There are two ways to set properties :
set(**kwarg)
set_ The attribute name ( Property value )
3、 ... and . Example
Use case insensitive in case drawing X11/CSS4 Color name . Use a scatter chart scatter
function , His return value is PathCollection
Is precisely Collection
Subclasses of classes , Next, a scatter diagram is used to demonstrate .
3.1edgecolors
edgecolors
Used to specify the edge color of the color block , If specified as None Then use matplotlib.rcParams
Internally determined value .
The colors you can use are shown in the link below :
In the original drawing, only linewidth
Parameters and facecolor
Parameters , So the marker point will only have one color .
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams['font.sans-serif'] = ['SimHei'] # Settings support Chinese
plt.rcParams['axes.unicode_minus'] = False # Set up - Number
plt.style.use('ggplot')
x = np.arange(15)
y = 2 * x + np.random.randint(-1, 5, size=15)
collection = plt.scatter(x, y, linewidths=4, s=8*(x+y), facecolor="blue", label=' Example scatter plot ')
plt.legend()
plt.title(" Original picture ", fontsize=25, fontweight="bold")
plt.show()
The original effect :
Add a statement collection.set_edgecolor('mediumseagreen')
Specify the edge color , The effect is as follows :
linewidth
Parameters and edgecolor
The two parameters should cooperate with each other to achieve the real effect . The color of one of the marks cannot be set separately .
You can pass an entire color sequence to set the edge color of multiple points , The sequence length does not have to be the same as the number of points , By default, the colors in the sequence are recycled , The effect is as follows :
3.2facecolors
facecolors
Used to specify the surface color of the color block , If specified as None Then use matplotlib.rcParams
Internally determined value . See for color details 3.1.
Use set()
Method to set a new surface color
collection.set(facecolor="gray")
Same as edgecolor Same parameter , You can set the cycle color , The effect is as follows :
3.3linewidths
linewidths
Parameter specifies the edge lineweight , You can specify a scalar or a scalar sequence . Use set_linewidth
Method to set , In addition to the two common setting methods, you can also use simplified statements set_lw
Method to set .
The new original image is as follows :
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams['font.sans-serif'] = ['SimHei'] # Settings support Chinese
plt.rcParams['axes.unicode_minus'] = False # Set up - Number
plt.style.use('ggplot')
x = np.arange(15)
y = 2 * x + np.random.randint(-1, 5, size=15)
collection = plt.scatter(x, y, linewidths=4, s=8*(x+y), edgecolors="cyan", facecolor="blue", label=' Example scatter plot ')
collection.set_lw(8)
plt.legend()
plt.title(" Original picture ", fontsize=25, fontweight="bold")
plt.show()
The effect is as follows :
3.4capstyle
capstyle
Parameter is used to set the style of both ends of the line , For details, see
3.5joinstyle
joinstyle
Parameter is used to set the connection mode of two line segments , For details, see
3.6antialiaseds
antialiaseds
Parameter is used to set whether anti aliasing is used for painting . The adjustment of this parameter has no obvious visual effect .
3.7cmap
cmap
Used to specify the color mapping table . This place needs attention , If you want to use it cmap The mapping table , The mapping method must be specified , Using the mapping table takes precedence over directly specifying the specific surface color , The edge color will not be affected .
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams['font.sans-serif'] = ['SimHei'] # Settings support Chinese
plt.rcParams['axes.unicode_minus'] = False # Set up - Number
plt.style.use('ggplot')
x = np.arange(15)
y = 2 * x + np.random.randint(-1, 5, size=15)
collection = plt.scatter(x, y, linewidths=4, s=8*(x+y), c=2*(x+y), edgecolors="cyan", facecolor="blue", label=' Example scatter plot ')
collection.set_cmap("PuOr")
plt.legend()
plt.title(" Original picture ", fontsize=25, fontweight="bold")
plt.show()
The effect is as follows :
3.8hatch
hatch
Parameter is used to set the hatch pattern , Optional :
/ - diagonal hatching
\ - back diagonal
| - vertical
+ - crossed
- - horizontal
x - crossed diagonal
o - small circle
O - large circle
. - dots
* - stars、
Pay attention to some points. , The first letter can be combined , If the same letter repeats , Will increase the shadow density of the pattern . Second, shadows are different from other attributes , Only... Can be specified for the entire collection , Instead, you cannot specify... For each member individually .
Use o
To add shadows , The effect is as follows :
Use ooo
To increase shadow density , The effect is as follows :
Use ox*
To combine shadows , The effect is as follows :
The color of the shadow and edgecolor Set the same color , Changing the edge line color can also affect the shadow color , The effect is as follows :
3.9linestyles
linestyles
Parameter is used to set the edge line style , See the link below for details :
Change the line style to dotted line , The effect is as follows :
3.10alpha
alpha
Parameter is often used to set the transparency of painted objects ,0-1 Value between . The effect is as follows :
版权声明
本文为[The big pig of the little pig family]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230617063213.html
边栏推荐
- 任意文件读取漏洞 利用指南
- Jerry's users how to handle events in the simplest way [chapter]
- Dirichlet prefix sum (number theory optimization formula sub complexity weapon)
- Full stack cross compilation x86 completion process experience sharing
- Charles 功能介绍和使用教程
- Understand the key points of complement
- Latex usage
- Learning notes 7-depth neural network optimization
- Derivation and regularization
- 997. Square of ordered array (array)
猜你喜欢
高价买来的课程,公开了!phper资料分享
C language - custom type
GO接口使用
VIM + ctags + cscope development environment construction guide
Deploy jar package
Solutions to common problems in visualization (VIII) solutions to problems in shared drawing area
Charles function introduction and use tutorial
Jerry's more accurate determination of abnormal address [chapter]
Yarn resource scheduler
Six practices of Windows operating system security attack and defense
随机推荐
精彩回顾|「源」来如此 第六期 - 开源经济与产业投资
Introduction to wechat applet, development history, advantages of applet, application account, development tools, initial knowledge of wxml file and wxss file
比深度学习更值得信赖的模型ART
How does the swagger2 interface import postman
微信小程序简介、发展史、小程序的优点、申请账号、开发工具、初识wxml文件和wxss文件
Jinglianwen technology - professional data annotation company and intelligent data annotation platform
The difference between restful and soap
关于JUC三大常用辅助类
Understand the key points of complement
Problems of class in C # and database connection
Jerry's more accurate determination of abnormal address [chapter]
Chapter 120 SQL function round
Can Jerry's AES 256bit [chapter]
Visual common drawing (III) area map
我的创作纪念日
Dirichlet prefix sum (number theory optimization formula sub complexity weapon)
Simple thoughts on the design of a microblog database
The courses bought at a high price are open! PHPer data sharing
[provincial election joint examination 2022 d2t1] card (state compression DP, FWT convolution)
Derivation and regularization