当前位置:网站首页>How to draw non overlapping bubble chart in MATLAB
How to draw non overlapping bubble chart in MATLAB
2022-07-03 17:57:00 【Tingwu】
For example, select indicators for the situation of higher education in countries around the world , use topsis I can't deal with it , You can get the education of various countries topsis fraction .
So how to use the graph to intuitively show the data results ? Considering the aesthetics , You can use non overlapping bubble charts , Bubble ( That is round ) Radius and topsis Score correlation , The size of the circle shows the country topsis Score level .
as follows :

matlab Implementation code :
First import the data :
clc,clear
D=xlsread(' ranking .xlsx',1,'B2:B16')';%topsis The top 15 fraction
[~,~,country]=xlsread(' ranking .xlsx',1,'A2:A16'); % The name of the country , For legend
Define bubble radius :
because topsis The scores are all in 0-1 Between , Is too small , So multiply by 100 As the bubble radius of various countries .
N=length(D); % The number of circles to draw
r=D*100; % Generation radius Define the side length of the picture :
If all circles do not overlap , The maximum length occupied ( That is, the side length of the graph ) Not more than the sum of circle diameters
w=2*sum(r); %** Area side length **Generate the first point , Draw a circle together :
Note that the first circle obviously can't make it run outside the figure , The radius length can be roughly defined as the center coordinate .
use [rand,rand,rand] Random color .
p=r(1)*ones(1,2); % Generate a random point
A=p'; % The coordinates of the first point are recorded into the matrix A in , Transpose operation
t=0:360;
patch(p(1)+r(1)*cosd(t),p(2)+r(1)*sind(t),[rand,rand,rand])
hold on The idea of generating non overlapping bubbles :
Generate points randomly , For example, start to generate the coordinates of the center of the third circle , Then judge the point and the 1,2 The distance between the coordinates of the center of a circle , Respectively cannot be less than r3+r1 and r3+r2. If it fails to meet the standard, continue to randomly generate points , If it meets the standard, store the coordinates of the point , And draw circles of random colors .
for ii=2:N
p=r(ii)+(w-2*r(ii)-47).*rand(1,2); % Generate a new random point ,rand(1,2) It means to produce one row and two columns (0,1) Random number between
while any((A(1,1:ii-1)-p(1)).^2+(A(2,1:ii-1)-p(2)).^2<=(r(1,1:ii-1)+r(ii)).^2) % Distance judgment does not overlap
p=r(ii)+(w-2*r(ii)-47).*rand(1,2);
end
A = [A,p']; % Save the new point to matrix A
patch(p(1)+r(ii)*cosd(t),p(2)+r(ii)*sind(t),[rand,rand,rand]); % Fill a circle
endBecause you want to make the non overlapping bubbles appear more compact in the figure , Constantly adjust parameters when generating coordinates ,-47 It looks better when .
@[email protected] Although it can still meet the current goal , But it's too unwise , There are at least two ways to improve this kind of diagram : Realize that each bubble is next to ; Customize a color matrix for the color of bubbles , If you can , Give Way topsis Score from high to low gradient color , Then the color column is shown on the next figure . If it is realized in the future , Come back and make up , Maybe not (?)
Of course , This picture can be found in tableau In the software :

The complete code is as follows :
clc,clear
D=xlsread(' ranking .xlsx',1,'B2:B16')';%topsis The top 15 fraction
[~,~,country]=xlsread(' ranking .xlsx',1,'A2:A16'); % The name of the country , For legend
N=length(D); % The number of circles to draw
r=D*100; % Generation radius
w=2*sum(r); %** Area side length **
p=r(1)*ones(1,2); % Generate a random point
A=p'; % The coordinates of the first point are recorded into the matrix A in , Transpose operation
t=0:360;
patch(p(1)+r(1)*cosd(t),p(2)+r(1)*sind(t),[rand,rand,rand])
%plot([0 w w 0 0],[0 0 w w 0]); % Draw an area box
hold on
for ii=2:N
p=r(ii)+(w-2*r(ii)-47).*rand(1,2); % Generate a new random point ,rand(1,2) It means to produce one row and two columns (0,1) Random number between
while any((A(1,1:ii-1)-p(1)).^2+(A(2,1:ii-1)-p(2)).^2<=(r(1,1:ii-1)+r(ii)).^2) % Distance judgment does not overlap
p=r(ii)+(w-2*r(ii)-47).*rand(1,2);
end
A = [A,p']; % Save the new point to matrix A
patch(p(1)+r(ii)*cosd(t),p(2)+r(ii)*sind(t),[rand,rand,rand]); % Fill a circle
end
legend(country,'Location','EastOutside') % Locate the legend
title('Top 15 countries with TOPSIS scores in 2020')
hold off
axis equalReference blog :MATLAB Draw a random circle that does not coincide in the region - Pangolin2 - Blog Garden
边栏推荐
- How to enforce parameters in PowerShell- How do I make parameters mandatory in PowerShell?
- 小程序 多tab 多swiper + 每个tab分页
- Wechat applet for the first time
- The gbase 8A database does not support the DB2 function value (column_name, 0) cluster syntax
- ArrayList analysis 3: delete elements
- 【统信UOS】扫描仪设备管理驱动安装
- SSL / bio pour OpenSSL Get FD
- (9) Opencv Canny edge detection
- Cloud primordial weekly | CNCF released the 2021 cloud primordial development status report, which was released on istio 1.13
- Tensorboard quick start (pytoch uses tensorboard)
猜你喜欢

Leetcode 538 converts binary search tree into cumulative tree -- recursive method and iterative method

Classroom attendance system based on face recognition tkinter+openpyxl+face_ recognition

Redis core technology and practice - learning notes (VI) how to achieve data consistency between master and slave Libraries

聊聊支付流程的设计与实现逻辑

win32:堆破壞的dump文件分析

Wechat applet for the first time

Micro service component sentinel console call

Five problems of database operation in commodity supermarket system

MySQL has been stopped in the configuration interface during installation

互联网医院HIS管理平台源码,在线问诊,预约挂号 智慧医院小程序源码
随机推荐
Global and Chinese health care OEM and ODM market status survey and investment planning recommendations report 2022-2028
Codeforces Round #803 (Div. 2) C. 3SUM Closure
[set theory] order relation: summary (partial order relation | partial order set | comparable | strictly less than | covering | hasto | total order relation | quasi order relation | partial order rela
毕业总结
Fedora 21 installs lamp host server
Analyse ArrayList 3: suppression d'éléments
Win32: dump file analysis of heap corruption
How to purchase Google colab members in China
Assembly for unloading Loadfrom() loaded assembly - unloading the assembly loaded with assembly LoadFrom()
[教程]在 CoreOS 上构建你的第一个应用
Implementation of Tetris in C language
[combinatorics] recursive equation (four cases where the non-homogeneous part of a linear non-homogeneous recursive equation with constant coefficients is the general solution of the combination of po
The second largest gay dating website in the world was exposed, and the status of programmers in 2022
[Tongxin UOS] scanner device management driver installation
SDNUOJ1015
TCP拥塞控制详解 | 3. 设计空间
聊聊支付流程的设计与实现逻辑
[combinatorics] generating function (summation property)
互联网医院HIS管理平台源码,在线问诊,预约挂号 智慧医院小程序源码
supervisor监控Gearman任务