In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "Matlab how to draw Sanji diagram", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "Matlab how to draw Sanji diagram" this article.
This time, the main purpose is to share a function written by myself, which is used to draw a Sanji diagram, and the effect looks like this:
First explain how to use the function (sankey2). The complete code of the function is placed at the end of the blog.
Detailed usage 1 use example
Create a new m file and run the following code
List= {'a1jewelry recorder 1 precepts aura;' a2pr recorders 1pia clockwork; 'a3mechelons beacons 1pyrrons;' a3locywagons 0.5pyrrymes; 'b1primes;' b1mins; 'b2pmpl;' b1pcc1pmpl; 'c1pmpl;' c1pmpl; 'c2pmlc1pmc1pmc1pl; c3pmlmlmlmcc1pmc1pmc1pmcc1pmlmlmlmlmlccccc1pmlmlmlmlmlmcccclmlmlmlmlmlmlmlmcccclmlmlmlmlmccclmlmlm 'Aphrodite pencils 2 pencils BBs;' Balls pencils 1. 5 pr é cors BBs; 'Bones pr é cor 1.5 pr é cor BBs;' Bones pr é cor 1.5 pr é cors; C é cor pr é cors 3.5 pence BBs;} Axis ([0Jing 2je 0jue 1]) sankeyHdl=sankey2 ([], 'XLim', [0Jing 2],' YLim', [0Jing 1], 'PieceWidth',0.15,'List',List,'Color', [0.3 meme 0.3 meme 0.7])
2 input parameters
2.1 necessary input parameters
There are a total of four necessary parameters. The first is the flow table ('List'), which can be imported from excel or written directly in the cell array as shown below:
List= {'a1jewelry recorder 1 precepts aura;' a2pr recorders 1pia clockwork; 'a3mechelons beacons 1pyrrons;' a3locywagons 0.5pyrrymes; 'b1primes;' b1mins; 'b2pmpl;' b1pcc1pmpl; 'c1pmpl;' c1pmpl; 'c2pmlc1pmc1pmc1pl; c3pmlmlmlmcc1pmc1pmc1pmcc1pmlmlmlmlmlccccc1pmlmlmlmlmlmcccclmlmlmlmlmlmlmlmcccclmlmlmlmlmccclmlmlm 'Aphrodite pencils 2 pencils BBs;' Balls pencils 1. 5 pr é cors BBs; 'Bones pr é cor 1.5 pr é cor BBs;' Bones pr é cor 1.5 pr é cors; C é cor pr é cors 3.5 pence BBs;}
The other three parameters are the x-axis range ('xLim'), the y-axis range (' YLim'), and the first parameter of the function. To draw the axes of the image, you can write the first parameter [] or gca in the current window.
2.2 Modification parameters
There are mainly the following, which are replaced with default values when not written.
Color Square Color
EdgeColor Square Edge Color
FontSize font size
FontColor font color
PieceWidth square width
Distance from edge to edge of Margin Sanji graph
Proportion of Sep vertical whitespace to total square length
Where Color can be a matrix of nx3 size, and the range of values in the matrix is [0prime1], for example:
List= {'a1jewelry recorder 1 precepts aura;' a2pr recorders 1pia clockwork; 'a3mechelons beacons 1pyrrons;' a3locywagons 0.5pyrrymes; 'b1primes;' b1mins; 'b2pmpl;' b1pcc1pmpl; 'c1pmpl;' c1pmpl; 'c2pmlc1pmc1pmc1pl; c3pmlmlmlmcc1pmc1pmc1pmcc1pmlmlmlmlmlccccc1pmlmlmlmlmlmcccclmlmlmlmlmlmlmlmcccclmlmlmlmlmccclmlmlm 'Aphrodite pencils 2 pencils BBs;' Balls pencils 1. 5 pr é cors BBs; 'Bones pr é cor 1.5 pr é cor BBs;' Bones pr é cor 1.5 pr é cors; C é cor pr é cors 3.5 pence BBs;} Axis ([0Pol 2] ColorList= [0.4600 0.5400 0.4600 0.5400 0.6800 0.4600 0.4100 0.4900 0.3600 0.3800 0.5300 0.8400 0.4400 0.5900 0.8700 0.7900 0.9300 0.6500 0.6400 0.8400 0.8300 0.5600 0.5300 0.5700 0.7600 0.8100 0.4300 0.5600 0.8600 0.9700 0.7800 0.5900 0.6500 0.8900 0.9100 0.5300 0.9300 0.5600 0.2500] SankeyHdl=sankey2 ([], 'XLim', [0jue 2],' YLim', [0d1], 'PieceWidth',0.15,'List',List,'Color',colorList)
3 output
The output of the function is as follows:
NameList is the name of each element, block is the graphic object of each square, connect is the graphical object of each connection, and txt is the text object of each label. We can do the following:
The original properties of graphic objects and text objects can still be used (color, position, transparency, edge thickness, etc.)
Suppose we try to manipulate the object on the basis of the following code:
List= {'a1jewelry recorder 1 precepts aura;' a2pr recorders 1pia clockwork; 'a3mechelons beacons 1pyrrons;' a3locywagons 0.5pyrrymes; 'b1primes;' b1mins; 'b2pmpl;' b1pcc1pmpl; 'c1pmpl;' c1pmpl; 'c2pmlc1pmc1pmc1pl; c3pmlmlmlmcc1pmc1pmc1pmcc1pmlmlmlmlmlccccc1pmlmlmlmlmlmcccclmlmlmlmlmlmlmlmcccclmlmlmlmlmccclmlmlm 'apocryphal 2] sankeyHdl=sankey2 ([],' XLim', [0pr 2]) sankeyHdl=sankey2 ([], 'XLim', [0pr 2]],' YLim', [0pr 1], 'PieceWidth',0.15,'List',List,'Color',colorList)
Operation 1 changes the fourth square color to red
SankeyHdl.block (4). FaceColor= [0.8 dint 0.3 pr 0.3]
Operation 2 turns the first connection of the 10th square red
SankeyHdl.connect (10Jing 1). FaceColor= [0.8 Jing 0.3 pr 0.3]
Operation 3 enlarges the 11th label text
SankeyHdl.txt (11). FontSize=40
Function complete code function sankeyHdl=sankey2 (varargin) if strcmp (get (varargin {1}, 'type'),' axes') ax=varargin {1}; else ax=gca;endhold (ax,'on')% if not set, the initial value of the image = prop.Color= [0L0L0]; prop.FontSize=10;prop.FontColor= [0L0L0]; prop.Xlim= [0L1]; prop.YLim= [0L1]; prop.PieceWidth=0.15;prop.List= []; prop.Margin=0.05;prop.Sep=1/8;prop.EdgeColor= [2000] % extract useful information from variable length variables = for i=1:length (varargin) tempVar=varargin {I}; if ischar (tempVar) & & length (tempVar) > 1 prop. (tempVar) = varargin {item1}; endend% traffic matrix construction = = nameList=unique ([prop.List (:, 1); prop.List (:, 3)], 'stable'); blockMat=zeros (length (nameList)); for i=1:size (prop.List,1) s=strcmp (nameList,prop.List (iQuery 1)) E=strcmp (nameList,prop.List (iMagne3)); blockMat (Spene) = prop.List {iMagne2}; endtotalFlow=max ([sum (blockMat,1); sum (blockMat,2)'], [], 1);% divided mulberry graph hierarchy = List_L=prop.List (:, 1); List_R=prop.List (:, 3); prop.layer= []; layerRoot= []; nasty 1 For i=length (List_R):-1:1 if ~ any (strcmp (List_L,List_R {I})) layerRoot= [layerRoot;find (strcmp (nameList,List_R {I})]; endendlayerRoot=unique (layerRoot,'stable'); while ~ isempty (List_L) layer_n= []; for i=length (List_L):-1:1 if ~ any (strcmp (List_R,List_L {I})) layer_n= [layer _ n Find (strcmp (nameList,List_L {I}))]; List_L (I) = []; List_R (I) = []; end end layer_n=unique (layer_n,'stable'); prop.layer (length (layer_n), n) = 0; prop.layer (1:length (layer_n), n) = layer_n; nasty 1% propend.layer (length (layerRoot), n) = 0 Prop.layer (1:length (layerRoot), n) = layerRoot;prop.layerNum=size (prop.layer,2);% draw Square = baseBlockX= [0meme 1]; baseBlockY= [0meme 1]; bnul=max (sum (prop.layer~=0,1));% block number upper limitbaseLenY= (diff (prop.YLim)-2*prop.Margin) / (bnul+ (bnul-1) * prop.Sep) * bnul;baseLenX= (diff (prop.XLim)-2*prop.Margin) / (prop.layerNum-0.5); colorIndex=1;for i=1:prop.layerNum tempY=prop.Margin ElemSet=prop.layer (prop.layer (:, I) = 0MagneI); flowSet=totalFlow (elemSet); offSet= (diff (prop.YLim)-2*prop.Margin-baseLenY/length (elemSet) * ((length (elemSet) + (length (elemSet)-1) * prop.Sep)) / 2; for j=1:length (elemSet) tempLenY=baseLenY./sum (flowSet). * flowSet (j); sankeyHdl.block (prop.layer (jjMagneI)) =. Fill (baseBlockX.*prop.PieceWidth+prop.Margin+ (iMur1) * baseLenX,... BaseBlockY.*tempLenY+tempY+offSet,... Prop.Color (colorIndex,:), 'EdgeColor',prop.EdgeColor); tempY=tempY+tempLenY+baseLenY/length (elemSet) * prop.Sep; colorIndex=mod (colorIndex,size (prop.Color,1)) + 1; endend% drawing connection layerList=prop.layer (:); for i=1:length (nameList) for j=i:length (nameList) if blockMat (iMaginj) ~ = 0 Hdl_L=sankeyHdl.block (I); Hdl_R=sankeyHdl.block (j) List_L=find (blockMat (blockMat:) = 0); list_R=find (blockMat (:, j) = 0); [~, pl,~] = intersect (layerList,list_L (:)); [, pr,~] = intersect (layerList,list_R (:)); list_L=layerList (sort (pl)); list_R=layerList (sort (pr)) Flow_L=blockMat (iJournal listings); flow_R=blockMat (list_R,j); XData_L=Hdl_L.XData;YData_L=Hdl_L.YData; XData_R=Hdl_R.XData;YData_R=Hdl_R.YData; xx= [XData _ L (1:2); XData_R (1:2)]'; k_L=find (list_L==j) K_R=find (list_R==i); yy= [YData _ L (1:2) + (YData_L (3:4)-YData_L (1:2)). / sum (flow_L). * sum (flow_L (1:k_L-1)) YData_R (1:2) + (YData_R (3:4)-YData_R (1:2). / sum (flow_R). * sum (flow_R (1:k_R-1))]'; xxq=XData_L (2): 0.01:XData_R (1); yyq=interp1 (xx,yy,xxq,'pchip'); tempColor=Hdl_L.FaceColor Width= (YData_R (3)-YData_R (1)). / sum (flow_R). * flow_R (Kendr); sankeyHdl.connect (iMagol) =. Fill ([xxq,xxq (end:-1:1)], [yyq,yyq (end:-1:1) + width], tempColor,'EdgeColor','none','FaceAlpha',0.3); end endend% drawing text for i=1:prop.layerNum tempY=prop.Margin; elemSet=prop.layer (prop.layer (:, I) ~ = 0Magi); flowSet=totalFlow (elemSet) OffSet= (diff (prop.YLim)-2*prop.Margin-baseLenY/length (elemSet) * ((length (elemSet) + (length (elemSet)-1) * prop.Sep)) / 2; for j=1:length (elemSet) tempLenY=baseLenY./sum (flowSet). * flowSet (j); sankeyHdl.txt (prop.layer (jMagee)) =. Text (prop.PieceWidth+prop.Margin+ (iMur1) * baseLenX,tempLenY/2+tempY+offSet, [', nameList {elemSet (j)}],... 'FontSize',prop.FontSize,'Color',prop.FontColor); tempY=tempY+tempLenY+baseLenY/length (elemSet) * prop.Sep; endendsankeyHdl.nameList=nameList';end uses sample codes List= {' snacks', 300 'food expenses'; 'drinks', 150 'food expenses'; 'fruit', 250 'food expenses'; 'canteen', 600 'food expenses' 'takeout', 400 'food expenses'; 'water charges', 90 'accommodation expenses'; 'electricity charges', 90 'accommodation expenses'; 'Internet expenses', 120 'accommodation expenses'; 'food expenses', 1700 'expenses'; 'accommodation expenses', 300 'expenses'} Axis sankeyHdl=sankey2 ([], 'XLim', [0Pere2],' YLim', [0L1], 'PieceWidth',0.15,'List',List,'Color',colorList) sankeyHdl.block (4). FaceColor= [0.8, sankeyHdl.txt (4). FontSize=40
Try to prove that the square painting looks more advanced and embellished:
The above is all the contents of the article "how to draw Sanji Pictures by Matlab". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.