How to change the mean value in the box plot?
Show older comments
Hi all, I want to replace the mean value in the boxplot to the RMSE. as figure illustrates.
Thank you in advance
3 Comments
the cyclist
on 19 May 2016
Ms. O, this is not twitter. Can you please give a little more detail, to make what you are trying to do clearer? Maybe show an example plot and how you want it to be different?
For example, do you want the whole box shifted? Or do you mean that there is a marker at the mean, but you want to show a marker at the RMSE value?
Don't make all of us guess at what you want.
Lilya
on 19 May 2016
dpb
on 19 May 2016
A boxplot marker is the median, NOT the mean...
To change this, you'll have to edit the box plot properties; there's a discussion in the help of finding the proper object via findobj and Tag values for the various options...
Accepted Answer
More Answers (1)
dpb
on 20 May 2016
Building off of Cyclist's demo and the comments I made earlier--
x = randn(1000,3);
boxplot(x)
h = findobj(gca,'Tag','Median');
set(h,{'xData'},{[1];[2];[3]}, ...
{'yData'},{[0.1];[0.2];[0.3]}, ...
'marker','*','color','k')

NB: the use of cell arrays to set multiple handles to disparate values in a single call to set. For demo I used hardcoded values but they can be variable, of course, and mat2cell can be helpful to build the proper shape.
2 Comments
Lilya
on 20 May 2016
dpb
on 21 May 2016
No problem, glad to help... :)
BTW, you can eliminate the temporary handle variable array by folding findobj into set...
set(findobj(gca,'Tag','Median') ...
{'xData'},{[1];[2];[3]}, ...
{'yData'},{[0.1];[0.2];[0.3]}, ...
'marker','*','color','k')
Like the objects themselves if not being used, I dislike keeping unneeded temporaries...
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!