Is there any way to have labels in color for boxplots?

It seems that boxplot function doesn't accept TeX Markup to give a specific color to labels of boxplot.
Any idea to give a color to a label using boxplot function?
boxplot([1 2 3 4], 'labels', {'a'}); % make 'a' red

 Akzeptierte Antwort

dpb
dpb am 22 Sep. 2018
Bearbeitet: dpb am 22 Sep. 2018
They're just XTickLabel values; set as desired as with any other axes.
For some reason TMW hasn't made a color property for them (yet); is a worthwhile extension request.
boxplot([1 2 3 4], 'labels', {'a'});
hAx=gca;
hAx.XAxis.TickLabelInterpreter='tex'; % make sure interpreter set
hAx.XTickLabel(1)={['\color{red}' hAx.XTickLabel{1}]}; % make 'a' red
Or, of course, you can embed the TeX string in the call if you create the axes first to set the 'Interpreter' property and if boxplot doesn't clear it internally (that I don't know, didn't test).

4 Kommentare

Thanks a lot! needed a minor adjustment:
boxplot([1 2 3 4], 'labels', {'a'});
hAx=gca;
hAx.XAxis.TickLabelInterpreter='tex'; % make sure interpreter set
hAx.XTickLabel={'\color{red}a'}; % make 'a' red
dpb
dpb am 22 Sep. 2018
Bearbeitet: dpb am 26 Sep. 2018
Actually the "adjustment" is to put back something I deleted with only one element thinking didn't need the addressing--but do need to dereference the cell array content of the existing label.
hAx.XTickLabel(1)={['\color{red}' hAx.XTickLabel{1}]}; % first red
it works thanks! (a '[' is needed though)
dpb
dpb am 26 Sep. 2018
Bearbeitet: dpb am 26 Sep. 2018
Correct, I'd already fixed the typo...don't recall just when I noticed it.
The key point was trying to make is that you can retrieve the already-set tick labels (or tick values) and apply the fixup to them instead or recreating the values. This may (or may not) in a given instance be of real savings just depending.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Distribution Plots finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 22 Sep. 2018

Bearbeitet:

dpb
am 26 Sep. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by