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 Exchange에서 Creating, 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