How can I change the color of the median line in boxchart?

28 次查看(过去 30 天)
I am creating a box plot using the "boxchart" function. How can I change the color of the median line?

采纳的回答

Star Strider
Star Strider 2021-7-12
It is not possible to change the colours, however it is possible to over-plot the median lines —
x = randn(5); % Create Data
figure
hbx = boxchart(x);
xMdn = median(x);
boxw = hbx.BoxWidth;
xd = 1:numel(hbx.XData);
hold on
plot(0.5*boxw*[-1;1]+xd, [1;1]*xMdn, '-r')
hold off
% get(hbx)
.
  6 个评论
Amelie
Amelie 2024-4-8
移动:Cris LaPierre 2024-4-8
I have a follow up question: Is it possible to exclude the median when plotting the boxchart? If so, how can I do it?
Many thanks for your help!
Star Strider
Star Strider 2024-4-8
移动:Cris LaPierre 2024-4-8
@Amelie
I’m not certain it can be excluded, however it can be hidden —
x = randn(5); % Create Data
figure
hbx = boxchart(x);
hbx.BoxMedianLineColor = 'g'; % Change 'boxchart' Median Line Colour
figure
hbx = boxchart(x);
hbx.BoxMedianLineColor = 'none'; % Hide 'boxchart' Median Line
.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Scatter Plots 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by