Skip to content

Commit

Permalink
Remove try/catch, in favour of using unique in the jitterstrength & m…
Browse files Browse the repository at this point in the history
…eandensitywidth
  • Loading branch information
mikelgg93 committed May 31, 2022
1 parent 8a707c7 commit e0955bc
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions Violin.m
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@

if isempty(args.ViolinColor)
Release= strsplit(version('-release'), {'a','b'}); %Check release
if str2num(Release{1})> 2019 | strcmp(version('-release'), '2019b')
if str2num(Release{1})> 2019 || strcmp(version('-release'), '2019b')
C = colororder;
else
C = lines;
Expand Down Expand Up @@ -201,15 +201,7 @@

%% Plot the data points within the violin area
if length(density) > 1
try
jitterstrength = interp1(value, density*width, data);
catch
% Error using matlab.internal.math.interp1
% Sample points must be unique and sorted in ascending order.
% Error in interp1 (line 188)
% VqLite = matlab.internal.math.interp1(X,V,method,method,Xqcol);
jitterstrength = mean(density*width);
end
jitterstrength = interp1(unique(value), unique(density*width), data);
else % all data is identical:
jitterstrength = density*width;
end
Expand Down Expand Up @@ -322,16 +314,7 @@
%% Plot the data mean
meanValue = mean(data);
if length(density) > 1
try
meanDensityWidth = interp1(value, density, meanValue)*width;
catch
% TODO:
% Error using matlab.internal.math.interp1
% Sample points must be unique and sorted in ascending order.
% Error in interp1 (line 188)
% VqLite = matlab.internal.math.interp1(X,V,method,method,Xqcol);
meanDensityWidth = mean(density*width);
end
meanDensityWidth = interp1(unique(value), unique(density), meanValue)*width;
else % all data is identical:
meanDensityWidth = density*width;
end
Expand Down Expand Up @@ -527,9 +510,9 @@


function set.ViolinAlpha(obj, alpha)
obj.ViolinPlotQ.FaceAlpha = .65; % reverse to .8?
obj.ViolinPlotQ.FaceAlpha = .65;
obj.ViolinPlot.FaceAlpha = alpha{1};
obj.ScatterPlot.MarkerFaceAlpha = 1;% reverse to alpha{1}? This increases visibility
obj.ScatterPlot.MarkerFaceAlpha = 1;
if ~isempty(obj.ViolinPlot2)
obj.ViolinPlot2.FaceAlpha = alpha{2};
obj.ScatterPlot2.MarkerFaceAlpha = alpha{2};
Expand Down

0 comments on commit e0955bc

Please sign in to comment.