当前位置:网站首页>Use of polarscatter function in MATLAB
Use of polarscatter function in MATLAB
2022-07-07 13:29:00 【jk_ one hundred and one】
Catalog
Use fill tags and set tag size
Use markers with different sizes and colors
Convert from degrees to radians before drawing
Modify after creating the scatter chart
Draw table data using custom tag size and color
polarscatter The function of the function is a scatter plot in polar coordinates .
grammar
polarscatter(theta,rho)
polarscatter(theta,rho,sz)
polarscatter(theta,rho,sz,c)
polarscatter(___,mkr)
polarscatter(___,'filled')
polarscatter(tbl,thetavar,rhovar)
polarscatter(tbl,thetavar,rhovar,'filled')
polarscatter(pax,___)
polarscatter(___,Name,Value)
ps = polarscatter(___)
explain
Vector and matrix data
polarscatter(theta,rho) draw theta Yes rho Graph , And a circular mark is displayed at each data point to show .theta and rho It must be a vector with the same length . Must be specified in radians theta.
To draw a set of points , Please put theta and rho Specify as equal length vector .
To draw multiple sets of points in the same polar coordinate area , Please put theta or rho At least one of is specified as a matrix .
polarscatter(theta,rho,sz) Set tag size , among sz Specify the area of each tag in square pounds . To draw all tags with the same size , Please put sz Specify as scalar . To draw markers with different sizes , Please specify as vector or matrix .
polarscatter(theta,rho,sz,c) Specify the marker color . You can assign a color to all tags , You can also change the color . for example , It can be done by putting c Designated as 'red' To draw all red circles .
polarscatter(___,mkr) Set the marking symbol . for example ,'+' Show cross marks . Specify the marker symbol after any combination of input parameters in the above syntax .
polarscatter(___,'filled') Fill the inside of the tag .
Table data
polarscatter(tbl,thetavar,rhovar) Draw a table tbl The variables in the thetavar and rhovar. To plot a data set , Please for thetavar Specify a variable , by rhovar Specify a variable . To plot multiple data sets , Please for thetavar、rhovar Or both specify multiple variables . If both parameters specify multiple variables , They must specify the same number of variables .( since R2021b Start offering )
polarscatter(tbl,thetavar,rhovar,'filled') Draw the specified variable in the table with a solid circle .( since R2021b Start offering )
The other options
polarscatter(pax,___) Will be in pax Specified polar coordinate area ( Instead of the current coordinate area ) Draw a picture in .
polarscatter(___,Name,Value) Use one or more names - Value pair group parameters modify the appearance of the scatter chart . for example , You can specify 'FaceAlpha' And a 0 and 1 Scalar values between , To use translucent markers .
ps = polarscatter(___) return Scatter Object or Scatter An array of objects . Creating Scatter Object can be used after ps Modify its appearance . About the attribute list , You can refer to Scatter attribute .
Example
Create a scatter diagram
Create a scatter plot in polar coordinates .
th = pi/4:pi/4:2*pi;
r = [19 6 12 18 16 11 15 15];
polarscatter(th,r)
As shown in the figure :
Use fill tags and set tag size
By specifying optional input parameters 'filled', Create a scatter chart with fill marks . Set the tag size to 75 Square pound .
th = linspace(0,2*pi,20);
r = rand(1,20);
sz = 75;
polarscatter(th,r,sz,'filled')
As shown in the figure :
Use markers with different sizes and colors
Create a scatter chart with markers of different sizes and colors . Specify the optional size and color input parameters as vectors . Use the uniqueness value in the color vector to specify the different colors you want . These values map to different colors in the color map .
th = pi/4:pi/4:2*pi;
r = [19 6 12 18 16 11 15 15];
sz = 100*[6 15 20 3 15 3 6 40];
c = [1 2 2 2 1 1 2 1];
polarscatter(th,r,sz,c,'filled','MarkerFaceAlpha',.5)
As shown in the figure :
Convert from degrees to radians before drawing
Create data with angle values in degrees . because polarscatter The angle value is required to be in radians , So use before drawing deg2rad Convert values to radians .
th = linspace(0,360,50);
r = 0.005*th/10;
th_radians = deg2rad(th);
polarscatter(th_radians,r)
As shown in the figure :
Merge two scatter charts
Use hold The command merges two scatter plots located in the same polar region . Add a legend containing the explanatory information of each figure .
th = pi/6:pi/6:2*pi;
r1 = rand(12,1);
polarscatter(th,r1,'filled')
hold on
r2 = rand(12,1);
polarscatter(th,r2,'filled')
hold off
legend('Series A','Series B')
As shown in the figure :
Modify after creating the scatter chart
Create a scatter chart , And assign the scatter object to the variable ps.
th = pi/6:pi/6:2*pi;
r = rand(12,1);
ps = polarscatter(th,r,'filled')
As shown in the figure :
ps =
Scatter with properties:
ThetaData: [0.5236 1.0472 1.5708 2.0944 2.6180 3.1416 3.6652 ... ]
RData: [0.8147 0.9058 0.1270 0.9134 0.6324 0.0975 0.2785 ... ]
ZData: [1x0 double]
SizeData: 36
CData: [0 0.4470 0.7410]
Marker: 'o'
MarkerEdgeColor: 'none'
MarkerFaceColor: 'flat'
LineWidth: 0.5000
Show all properties
After you create a scatter object, you can use ps Modify its properties .
ps.Marker = 'square';
ps.SizeData = 200;
ps.MarkerFaceColor = 'red';
ps.MarkerFaceAlpha = .5;
As shown in the figure :
Draw the data in the table
since R2021b Start offering , A convenient way to draw data in a table is to pass the table to polarscatter function , And specify the variables to draw . for example , Create a table with three variables , And draw 'Th' and 'R1' Variable .
% Create a table of random numbers
Th = linspace(0,2*pi,50)';
R1 = randi([0 10],50,1);
R2 = randi([20 30],50,1);
tbl = table(Th,R1,R2);
% Create polar scatter chart
polarscatter(tbl,'Th','R1')
As shown in the figure :
You can also draw multiple variables at the same time . for example , By way of rvar The parameter is specified as a cell array {'R1','R2'} To plot two sets of radius values . then , Add a legend . The legend label matches the variable name .
polarscatter(tbl,'Th',{'R1','R2'})
legend
As shown in the figure :
Draw table data using custom tag size and color
since R2021b Start offering , One way to draw data in a table and customize colors and marker sizes is to set ColorVariable and SizeData attribute . You can call polarscatter Function, set these properties to the name - Value parameter , Or later in Scatter Set them on the object .
for example , Create a table containing three random number variables , And draw with fill marks Th and R Variable . By designation ColorVariable name - Value parameter to change the marker color . take Scatter Object returned as s, So that you can set other properties later .
Th = linspace(0,2*pi,50)';
R = randi([0 10],50,1);
Colors = rand(50,1);
tbl = table(Th,R,Colors);
s = polarscatter(tbl,'Th','R','filled','ColorVariable','Colors');
As shown in the figure :
By setting SizeData attribute , Change the tag size to 100 pounds .
s.SizeData = 100;
As shown in the figure :
Input parameter description
theta - theta value
Theta value , Specify as scalar 、 Vector or matrix . Scatter object ThetaData Property store theta value .theta The size and shape of depends on the shape of the data . The following table describes the most common cases .
Drawing type | How to specify coordinates |
---|---|
Single point | take theta and rho Specify as scalar . for example : polarscatter(pi/2,0.5) |
A set of points | Appoint theta and rho Is any combination of row vectors or column vectors of the same length . for example : polarscatter([0 pi/4 pi/2],[1; 2; 3]) |
Multiple groups of dots with different colors | If all groups share the same theta or rho value , Please specify the shared coordinates as a vector , Specify other coordinates as a matrix . The length of the vector must match one of the dimensions of the matrix . for example : polarscatter([0 pi/4 pi/2],[4 5 6; 7 8 9])If the matrix is a square matrix ,polarscatter A separate set of points will be drawn for each column in the matrix . You can also specify theta and rho Is a matrix of the same size . In this case ,polarscatter draw theta Each column pair of rho Graph of the corresponding column of . for example : polarscatter([0 pi/6 pi/2; pi/8 pi/4 pi],[1 2 3; 4 5 6]) |
rho - rho value
rho value , Specify as scalar 、 Vector or matrix . Scatter object RData Property store rho value .rho The size and shape of depends on the shape of the data . The following table describes the most common cases .
Drawing type | How to specify coordinates |
---|---|
Single point | take theta and rho Specify as scalar . for example : polarscatter(pi/2,0.5) |
A set of points | Appoint theta and rho Is any combination of row vectors or column vectors of the same length . for example : polarscatter([0 pi/4 pi/2],[1; 2; 3]) |
Multiple groups of dots with different colors | If all groups share the same theta or rho value , Please specify the shared coordinates as a vector , Specify other coordinates as a matrix . The length of the vector must match one of the dimensions of the matrix . for example : polarscatter([0 pi/4 pi/2],[4 5 6; 7 8 9])If the matrix is a square matrix ,polarscatter A separate set of points will be drawn for each column in the matrix . You can also specify theta and rho Is a matrix of the same size . In this case ,polarscatter draw theta Each column pair of rho Graph of the corresponding column of . for example : polarscatter([0 pi/6 pi/2; pi/8 pi/4 pi],[1 2 3; 4 5 6]) |
sz - Tag size
Tag size , Specify as numeric scalar 、 vector 、 Matrix or empty array ([]). Size controls the area of each marker ( In square pounds ). An empty array specifies 36 The default size of the pound . The way you specify the size depends on how you specify theta and rho, And the desired drawing appearance . The following table describes the most common cases .
Desired tag size | theta and rho | sz | Example |
---|---|---|---|
All points have the same size | in the light of theta and rho Any effective combination of said vectors or matrices . | Scalar | take theta Specify as vector , take rho Specify as matrix , take sz Specify as scalar . th = [0 pi/6 pi/2]; r = [1 2; 2 4; 5 6]; polarscatter(th,r,100) |
The size of each point is different | Vectors of the same length |
| take theta、rho and sz Specify as vector . th = [0 pi/6 pi/2]; r = [1; 2; 3]; sz = [50 500 100]; polarscatter(th,r,sz) take theta and rho Specify as vector , take sz Specify as matrix . th = [0 pi/6 pi/2]; r = [1; 2; 3]; sz = [50 500 100; 300 1000 200]; polarscatter(th,r,sz) |
The size of each point is different | x or y At least one of them is a matrix for plotting multiple data sets |
| take theta Specify as vector , take rho Specify as matrix , take sz Specify as vector . th = [0 pi/6 pi/2]; r = [1 2; 2 4; 5 6]; sz = [50 500 1000]; polarscatter(th,r,sz) take theta Specify as vector , take rho Specify as matrix , take sz Specify as and rho A matrix of the same size . th = [0 pi/6 pi/2]; r = [1 2; 2 4; 5 6]; sz = [50 500; 1000 2000; 100 300]; polarscatter(th,r,sz) |
c - Mark the color
Mark the color , Specify as color name 、RGB A triple 、RGB Triplet matrix or vector composed of color map index .
Color name - Color name ( Such as 'red') Or short name ( Such as 'r').
RGB A triple - Three element row vector , Its elements specify the color medium red 、 green 、 The intensity of the blue component . The strength value must be in [0,1] Within the scope of , for example [0.4 0.6 0.7].RGB Triples are useful for creating custom colors .
RGB Triple matrix - Three column matrix , Each of these lines is a RGB A triple .
Vector composed of color map index - Numeric vectors , Its length is equal to theta and rho The vectors are the same .
The way you specify colors depends on the desired color scheme and whether to draw a set of coordinates or multiple sets of coordinates . The following table describes the most common cases .
Color scheme | How to specify colors | Example |
---|---|---|
Use one color for all points . | Specify a color name or short name from the following table , Or specify a RGB A triple . | Draw a set of points , And specify the color as 'red'. th = [0 pi/6 pi/2]; r = [1 2 3]; c = 'red'; polarscatter(th,r,[],c) Draw two sets of points , And use a RGB The triplet specifies the color as red . th = [0 pi/6 pi/2]; r = [1 2; 2 4; 5 6]; c = [1 0 0]; polarscatter(th,r,[],c) |
Use a color map to assign different colors to each point . | Specify a row vector or column vector consisting of numbers . Index of values in the current color map array . The minimum value is mapped to the first line in the color map , The maximum value is mapped to the last line . The intermediate value is linearly mapped to the intermediate line . If the plot has three points , Please specify a column vector , To ensure that these values are interpreted as color map indexes . Only when the theta、rho and sz When both are vectors , To use this method . | Create a vector c, It specifies four color map indexes . Draw four points using the colors in the current color map . then , Change the color map to winter. th = [0 pi/6 pi/2 2*pi/3]; r = [1 2 3 4]; c = [1 2 3 4]; polarscatter(th,r,[],c) colormap(gca,'winter') |
Create a custom color for each point . | Specify a by RGB Composed of triples m×3 matrix , among m Is the number of points in the graph . Only when the theta、rho and sz When both are vectors , To use this method . | Create a matrix c, It specifies four colors RGB A triple . Then use these colors to create and draw four points . th = [0 pi/6 pi/2 2*pi/3]; r = [1 2 3 4]; c = [1 0 0; 0 1 0; 0 0 1; 0 0 0]; polarscatter(th,r,[],c) |
Create a different color for each dataset . | Specify a by RGB Composed of triples n×3 matrix , among n For the number of data sets . Only when the theta、rho or sz When at least one of them is a matrix , To use this method . | Create one that contains two RGB Matrix of triples c. Then use these colors to draw two data sets . th = [0 pi/6 pi/2]; r = [1 2; 2 4; 5 6]; c = [1 0 0; 0 0 1]; polarscatter(th,r,[],c) |
The color names of common colors and RGB A triple
Color name | Short name | RGB A triple | Hexadecimal color code | appearance |
---|---|---|---|---|
'red' | 'r' | [1 0 0] | '#FF0000' | |
'green' | 'g' | [0 1 0] | '#00FF00' | |
'blue' | 'b' | [0 0 1] | '#0000FF' | |
'cyan' | 'c' | [0 1 1] | '#00FFFF' | |
'magenta' | 'm' | [1 0 1] | '#FF00FF' | |
'yellow' | 'y' | [1 1 0] | '#FFFF00' | |
'black' | 'k' | [0 0 0] | '#000000' | |
'white' | 'w' | [1 1 1] | '#FFFFFF' |
Here are MATLAB The default color used in many types of drawings RGB Triples and hex color codes .
RGB A triple | Hexadecimal color code | appearance |
---|---|---|
[0 0.4470 0.7410] | '#0072BD' | |
[0.8500 0.3250 0.0980] | '#D95319' | |
[0.9290 0.6940 0.1250] | '#EDB120' | |
[0.4940 0.1840 0.5560] | '#7E2F8E' | |
[0.4660 0.6740 0.1880] | '#77AC30' | |
[0.3010 0.7450 0.9330] | '#4DBEEE' | |
[0.6350 0.0780 0.1840] | '#A2142F' |
mkr - The sign
The sign , Specify as one of the marking symbols listed in the following table .
Mark | explain | Generated tags |
---|---|---|
'o' | circle | |
'+' | plus | |
'*' | asterisk | |
'.' | spot | |
'x' | Cross | |
'_' | Horizontal lines | |
'|' | Vertical lines | |
's' | square | |
'd' | The diamond | |
'^' | Upper triangle | |
'v' | Lower triangle | |
'>' | Right triangle | |
'<' | Left triangle | |
'p' | Pentagonal | |
'h' | hexagon |
Scatter object Marker Attributes store tag symbols .
tbl - Source table
The source table containing the data to plot . Specify this parameter as a table or schedule .
thetavar - contain theta Table variables of values
contain theta Table variables of values , Specify an index for one or more table variables .
Specify table index
Use any of the following indexing schemes to specify one or more of the required variables .
Indexing scheme | Example |
---|---|
Variable name :
|
|
Variable number :
|
|
Logical vector :
|
|
Variable type :
|
|
Plot your data
The specified table variable can contain any numeric data type .
To plot a data set , Please for thetavar Specify a variable , by rhovar Specify a variable . for example , Create a table with three variables . draw Th and R1 Variable .
% Create a table of random numbers
Th = linspace(0,2*pi,10)';
R1 = randi([0 10],10,1);
R2 = randi([20 30],10,1);
tbl = table(Th,R1,R2);
% Create polar scatter chart
polarscatter(tbl,'Th','R1')
To plot multiple data sets together , Please for thetavar、rhovar Or both specify multiple variables . If you specify multiple variables for both parameters , Then the number of variables of each parameter must be the same .
for example , stay theta Draw on the axis Th Variable , stay r Draw on the axis R1 and R2 Variable .
polarscatter(tbl,'Th',{'R1','R2'})
You can also use different indexing schemes for table variables . for example , take thetavar Specify as variable name , take rhovar Specify as index number .
polarscatter(tbl,'Th',2)
rhovar - contain rho Table variables of values
contain rho Table variables of values , Specify an index for one or more table variables .
Specify table index
Use any of the following indexing schemes to specify one or more of the required variables .
Indexing scheme | Example |
---|---|
Variable name :
|
|
Variable number :
|
|
Logical vector :
|
|
Variable type :
|
|
边栏推荐
- 数字ic设计——SPI
- Esp32 ① compilation environment
- JNA learning notes 1: Concepts
- MongoDB 分片总结
- 分屏bug 小记
- Vscade editor esp32 header file wavy line does not jump completely solved
- 分布式事务解决方案
- Realbasicvsr test pictures and videos
- 我那“不好惹”的00后下属:不差钱,怼领导,抵制加班
- Cloud detection 2020: self attention generation countermeasure network for cloud detection in high-resolution remote sensing images
猜你喜欢
随机推荐
解决缓存击穿问题
Read PG in data warehouse in one article_ stat
Simple and easy-to-use code specification
MongoDB内部的存储原理
Esp32 series column
LIS 最长上升子序列问题(动态规划、贪心+二分)
regular expression
【学习笔记】AGC010
日本政企员工喝醉丢失46万信息U盘,公开道歉又透露密码规则
Some principles of mongodb optimization
提升树莓派性能的方法
Go language learning notes - structure
How far can it go to adopt a cow by selling the concept to the market?
error LNK2019: 无法解析的外部符号
[Presto profile series] timeline use
将数学公式在el-table里面展示出来
ESP32构解工程添加组件
Mongodb meets spark (for integration)
飞桨EasyDL实操范例:工业零件划痕自动识别
Introduce six open source protocols in detail (instructions for programmers)