I want to plot the Violin Graph with my data, but I am not able to get how to plot those graphs. I saw the Distribution Plot,Distribution Plot in File exchange for Matlab, but I am unable to find the place to input my x-values and y-values.

 採用された回答

Matt J
Matt J 2020 年 1 月 29 日
編集済み: Matt J 2020 年 1 月 29 日

2 投票

13 件のコメント

Joe Sheppard
Joe Sheppard 2021 年 4 月 22 日
Hey, I want to start using this more but I'm having trouble changing the color of the individual data points within the body of the violin. The face color and edge color of the violins have options to change in matlab property editor, but not the points themselves. Do you know a way around this?
Thanks for recommending this code by the way, I like it, just need to get around this small issue.
Matt J
Matt J 2021 年 4 月 22 日
編集済み: Matt J 2021 年 4 月 22 日
The output object has a handle to the scatter plot of the data points which you can use to adjust this, e.g.,
violins = violinplot(data, cats, _____);
violins(1).ScatterPlot.MarkerFaceColor='red';
Camilla Ancona
Camilla Ancona 2021 年 5 月 30 日
編集済み: Camilla Ancona 2021 年 5 月 30 日
I'm trying to visualize my data by means of this package, but I was wondering if there is a way to color differently the datapoints accordingly to their belonging of a certain range of equivalently the area of the violin. this is my attemot in substituiting the CData matrix with arranged RGB triplets but this approach does not works
vs = violinplot(data,[],'Width',0.2,'Bandwidth',0.3,'ViolinColor',[0 0 1],'ViolinAlpha',0.5,'EdgeColor',[0 0 1],'BoxColor',[0 0 0],'MedianColor',[1 0 0]);
hold on
h = vs(1).ScatterPlot;
cdata = vs.ScatterPlot.CData;
c = repmat(cdata,[1446 1]);
c(1:freq_new_net(1),:) = repmat([1 0 0],[freq_new_net(1) 1]);
c(freq_new_net(1)+1:freq_new_net(1)+freq_new_net(2),:) = repmat([1 1 0],[freq_new_net(2) 1]);
c(freq_new_net(1)+freq_new_net(2)+1:freq_new_net(1)+freq_new_net(2)+freq_new_net(3),:) = repmat([1 1 1],[freq_new_net(3) 1]);
c(freq_new_net(1)+freq_new_net(2)+freq_new_net(3)+1:freq_new_net(1)+ freq_new_net(2)+freq_new_net(3)+freq_new_net(4),:) = repmat([0 0 1],[freq_new_net(4) 1]);
c(freq_new_net(1)+freq_new_net(2)+freq_new_net(3)+freq_new_net(4)+1:1446,:) = repmat([0 1 0],[freq_new_net(5) 1]);
h.CData = c;
vs.ScatterPlot.CData = c;
Matt J
Matt J 2021 年 5 月 30 日
You haven't shown us the result of the code, nor described ot us how the result differs from your expectations, so we can't know what "does not work" means.
Camilla Ancona
Camilla Ancona 2021 年 5 月 30 日
I am sorry to not have been clear before, this is the violin plot resulting from the code posted before. i would like to color the datapoints with different colors accordingly to their belonging to a certain range(e.g., datapoints ranging betweeen 0-0.2 in red, between 0.2-0.4 in green and so on) or even better if I could color differently the section of the violin area with different colors (with the same reasoning of the datapoints mentioned above). thank you
Matt J
Matt J 2021 年 5 月 31 日
編集済み: Matt J 2021 年 5 月 31 日
In the scatter plot handle, you need to set MarkerFaceColor='flat':
v=violinplot(rand(100,1)); v.ShowData=true; v.ViolinAlpha=0.1;
h=v.ScatterPlot; h.MarkerFaceAlpha=0.4; h.MarkerFaceColor='flat';
h.CData=repmat(h.CData,numel(h.YData),1);
index=h.YData<0.5; h.CData(index,1)=1; h.CData(index,2)=0; h.CData(index,3)=0;
Camilla Ancona
Camilla Ancona 2021 年 5 月 31 日
thank you vey much! this has been very helpful
Daniel Madigan
Daniel Madigan 2022 年 5 月 23 日
I am consistently having a problem with the 'varargin' variable, even when follwing examples exactly....can anyone explain?
Matt J
Matt J 2022 年 5 月 23 日
I am consistently having a problem with the 'varargin' variable, even when follwing examples exactly....can anyone explain?
Perhapsw, if you show what you did, and what the result was.
AARISH NAWAZ
AARISH NAWAZ 2022 年 5 月 24 日
Hi I was able to use the code from the github library, I want to plot multiple violin plots at different x values (eg 0, 1, 2, 3, 4) but when I use this function it automatically plots at x=1 and I am unable to change the X position. Can u please help me, how can i change the X position)
Matt J
Matt J 2022 年 5 月 24 日
編集済み: Matt J 2022 年 5 月 24 日
I suggest you show us the code you used to attempt the plot, and attach the input data that will let us run it.
AARISH NAWAZ
AARISH NAWAZ 2022 年 5 月 24 日
編集済み: AARISH NAWAZ 2022 年 5 月 25 日
I have plotted a red line first (see attchment) and using hold on I plotted the violin plots on the same figure but it starts with 1 I want it to start from zero (I want to move each violin plot to one place left).
@Matt J I have attached the matlab file and the .mat data file. Please have a look
Thanking you in anticipation
AARISH NAWAZ
AARISH NAWAZ 2022 年 5 月 26 日
How to change Violin Plot axis? I am able to plot it but It starts with one by default, I want it to start from zero. Please see the previous comment from me. You can find all the codes and data required to understand the question. @Matt J

サインインしてコメントする。

その他の回答 (2 件)

Holger Hoffmann
Holger Hoffmann 2021 年 12 月 9 日
編集済み: Holger Hoffmann 2021 年 12 月 9 日

0 投票

Hi - you may also consider to use this one and modify it: Violin Plot - File Exchange - MATLAB Central (mathworks.com)
Adam Danz
Adam Danz 2024 年 10 月 9 日

0 投票

MATLAB now has a violinplot, introduced in R2024b.
See also swarmchart
tiledlayout(3,1)
violinplot(nexttile,rand(20,3).*[.8 1. 1.2]+[-1 0 1],'Orientation','horizontal')
violinplot(nexttile,0,'DensityDirection','positive')
hold on
violinplot(2,'DensityDirection','negative')
violinplot(nexttile,magic(4));

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

製品

質問済み:

2020 年 1 月 27 日

回答済み:

2024 年 10 月 9 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by