Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to draw Violin Picture based on Matlab

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

Today, Xiaobian will share with you the relevant knowledge points on how to draw violin diagrams based on Matlab. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you will gain something after reading this article. Let's find out together.

How to use violinChart

Write a matlab drawing violin diagram function:

1. The fiddle-shaped region in the figure is a nuclear density curve.

2. White squares are 25%, 75% quantiles.

3. The middle line is the median.

4. White points are outlier points.

5. The vertical black lines are the upper and lower limits of the points after removing outliers.

Base usage, Y is matrix X=1:5;Y=randn(100,5);violinChart(gca,X,Y,[0 0.447 0.741], 0.6);

X |abscissa.

Y |Data sets.

FaceColor |The color, for example, is [0 0.447 0.741].

width |The width of the violin graph, which is 0.6 here, is 0.6 times the distance between two violin graphs as the upper limit of the probability density of 1.

Base usage, Y is vector, X is label X=[1.* ones(1,50),2.* ones(1,30),3.* ones(1,20),4.* ones(1,50),5.* ones(1,50)];Y=randn(1,200)+sin(X);violinChart(gca,X,Y,[0 0.447 0.741]);

Basic use, multiple images drawn, and add legend X1=[1:2:7,13];Y1=randn(100,5)+sin(X1);X2=2:2:10;Y2=randn(100,5)+cos(X2); figureHDL1 =violinChart(gca,X1,Y1,[0 0.447 0.741]);Hdl2=violinChart(gca,X2,Y2,[0.850 0.325 0.098]);legend([Hdl1.F_legend,Hdl2.F_legend],{'randn+sin(x)','randn+cos(x)'});

violinChart complete function

If the function is updated, the updated version will be placed in the compressed file shown at the end of this article.

function Hdl=violinChart(ax,X,Y,FaceColor,width)% @author slanderer % Hdl: Returned graphic object handle structure % - ------------------------- -% Hdl.F_density(i) | patch | Nuclear density distribution % Hdl.F_outlier(i) | scatter |Outlier point % Hdl.F_range95(i) | line | Maximum and minimum after removing outliers % Hdl.F_quantile(i)| patch | Quartile Box % Hdl.F_medianLine(i)| line | Median %% Hdl.F_legend | patch | Graph objects used to generate legend % - ------------------------- -% Generate legend as follows: % Hdl1=violinChart(ax,X,Y,... ...)% Hdl2=violinChart(ax,X,Y,... ...)% ... ...% legend([Hdl1,Hdl2,... ...], {Name1,Name2,...})% =========================================================== % Y1=randn(100,5)+sin(X1);% X2=2:2:10;% Y2=randn(100,5)+cos(X2);% % Hdl1=violinChart(gca,X1,Y1,[0 0.447 0.741],0.5);% Hdl2=violinChart(gca,X2,Y2,[0.850 0.325 0.098],0.5);% legend([Hdl1.F_legend,Hdl2.F_legend],{'randn+sin(x)','randn+cos(x)'});if nargin2 theme.AxesTheme=varargin{3};end% Start Styling ====================================================================ax.Box ='off ';ax.YGrid ='on'; ax.XGrid ='on ';ax.GridLineStyle ='--';ax.LineWidth=1.2;% Theme Styling Tm=load ('themeCSS. mat');Tm=Tm.theme;ax.Color=Tm. (theme.AxesTheme).Color;ax.TickLength=Tm. (theme.AxesTheme).TickLength;ax.GridColorMode=Tm. (theme.AxesTheme).GridColorMode;ax.GridColor=Tm. (theme.AxesTheme).GridColor;ax.GridAlpha=Tm. (theme.AxesTheme).GridAlpha;ax.XColor=Tm. (theme.AxesTheme).XColor;ax.YColor=Tm. (theme.AxesTheme).YColor;ax.TickDir=Tm. (theme.AxesTheme).TickDir;ax.ColorOrder=Tm. (theme.AxesTheme).ColorOrder;for i=1:length(HDLset) for j=1:length(HDLset(i).F_density) HDLset(i).F_density(j).FaceColor=ax.ColorOrder(mod(i-1,size(ax.ColorOrder,1))+1,:); HDLset(i).F_density(j).EdgeColor=[.1,.1,.1]; f_max=(max(HDLset(i).F_density(j).XData)-min(HDLset(i).F_density(j).XData))/2; x_mid=(max(HDLset(i).F_density(j).XData)+min(HDLset(i).F_density(j).XData))/2; HDLset(i).F_quantile(j).XData=x_mid+0.4.* f_max.* [-1 1 1 -1]; HDLset(i).F_quantile(j).FaceColor=[1 1 1].* 0.95; HDLset(i).F_medianLine(j).XData=x_mid+0.4.* f_max.* [-1 1]; HDLset(i).F_medianLine(j).LineWidth=2; HDLset(i).F_medianLine(j).Color=[0.3,0.3,0.3]; HDLset(i).F_outlier(j).CData=Tm. (theme.AxesTheme).EdgeColor; end endif ~isempty(ax.Legend) ax.Legend.Box='off'; ax.Legend.FontSize=12; if mean(ax.Color)>0.6 ax.Legend.TextColor=ax.XColor; else ax.Legend.TextColor=[0.9 0.9 0.9]; end if ~isempty(regexpi(ax.Legend.Location,'out', 'once')) ax.Legend.TextColor=ax.XColor; ax.Legend.Title.FontSize=14; end ax.Legend.AutoUpdate='off'; end The above is "How to draw violin diagram based on Matlab" All the contents of this article, thank you for reading! I believe everyone has a great harvest after reading this article. Xiaobian will update different knowledge for everyone every day. If you want to learn more knowledge, please pay attention to 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report