Boxplot group labels turning interpreter off + Displaying boxplot symbols.

12 views (last 30 days)
Hi,
I have a large number of groups of data that I want to plot using boxplot. The labels contain signs like '_' followed by letters or numbers. '_' causes the letters and numbers appear as subscript due to latex interpreter being on. How can I turn of Latex interptreter for the labels?
Also, since boxplot might be new to some people I want the symbols, whiskers, box, mean and median, to be shown like a legend in the boxplot. Is there an easy way to do that?
Thank you in advance
Edit: I will post the code.
boxplot(predictions{1}.YPredicted1,predictions{1}.Sample)% predictions{1}.Ypredicted is a a column containing numbers and...
% predictions{1}.Sample contains the corresponding group names
set(gca,'FontSize',10,'XTickLabelRotation',90) % group names rotatedby 90°
%How do I turn ob latex interpreter?
%%
% looking for objects in the boxplot
L1 = findobj(gca,'Tag','Median');
L2 = findobj(gca,'Tag','Box');
L3 = findobj(gca,'Tag','Upper Whisker');
L4 = findobj(gca,'Tag','Outliers');
L5 = findobj(gca,'Tag','Mean');
%%
%using the objects write legends
legend([L1(1,1),L2(1,1),L3(1,1)],{'Median','25-75 Percentile','Data boundary'},'Location','Northwest','FontSize',14)
Running the last line leads to the following error:
Index in position 1 exceeds array bounds.
Error in ScriptName (line 34)
legend([L1(1,1),L2(1,1),L3(1,1)],{'Median','25-75 Percentile','Data
boundary'},'Location','Northwest','FontSize',14); %,L4(1,1)Outliers

Accepted Answer

Cris LaPierre
Cris LaPierre on 6 Aug 2021
How can I turn of Latex interptreter for the labels?
Set the 'Interpreter' property to 'none'.
xlabel('All_Vehicles',"Interpreter","none")
Also, since boxplot might be new to some people I want the symbols, whiskers, box, mean and median, to be shown like a legend in the boxplot. Is there an easy way to do that?
No. Your approach is likely the best you can do in a legend. Your code does not return an error when run on an example from the boxplot documentation page. Perhaps your boxplots of your data do not have upper whiskers?
load carsmall
boxplot(MPG)
xlabel('All_Vehicles',"Interpreter","none")
ylabel('Miles per Gallon (MPG)')
title('Miles per Gallon for All Vehicles')
L1 = findobj(gca,'Tag','Median');
L2 = findobj(gca,'Tag','Box');
L3 = findobj(gca,'Tag','Upper Whisker');
L4 = findobj(gca,'Tag','Outliers');
L5 = findobj(gca,'Tag','Mean');
legend([L1,L2,L3],{'Median','25-75 Percentile','Data boundary'},'Location','Northwest','FontSize',14)

More Answers (0)

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!