Plotting boxplots at specific x axis locations over other data

I would like to plot boxplots at the specific x axis locations of 0, 14, 19, 26 (days), over existing data. In the figure it shows that the boxplots get plotted at the start, is there a way to specify their location or does a second x axis need to be created?

 Accepted Answer

You can specify the locations of the boxplots in the x direction using the 'Positions' argument:
ROSdata = readtable('ROS_data.xlsx');
bothgrouped0hr = readtable('both_grouped_0hr.xlsx');
yyaxis left
plot(ROSdata.Time,ROSdata.ROSpercell)
hold on
plot(ROSdata.Time,ROSdata.Expulsion)
hold on
yyaxis right
boxA = boxplot(bothgrouped0hr.Turbinaria,bothgrouped0hr.Day,'Positions',[0, 14, 19, 26]);
hold on
boxB = boxplot(bothgrouped0hr.Duncan,bothgrouped0hr.Day,'Positions',[0, 14, 19, 26]);

4 Comments

Perfect, thankyou!
Any idea why adding a yline to the graph would erase previous plotting? I need to add a couple of extra lines on top of current plotting. Please see attached
The yline was at 1.41. The YLimits of the (left) axes were from 0 to 2.5e-14. I guess the yline is supposed to be at 1.41e-14.
In other words, adding the yline didn't erase the previous lines, it just increased the upper YLimit by nearly 14 orders of magnitude, so that the previous lines were so close to the bottom of the plot they couldn't be seen anymore.
ROSdata = readtable('ROS_data.xlsx');
bothgrouped0hr = readtable('both_grouped_0hr.xlsx');
yyaxis left
hold on
plot(ROSdata.Time,ROSdata.ROSpercell)
plot(ROSdata.Time,ROSdata.Expulsion)
% threshold = yline(1.41)
threshold = yline(1.41e-14)
threshold =
ConstantLine with properties: InterceptAxis: 'y' Value: 1.4100e-14 Color: [0.1500 0.1500 0.1500] LineStyle: '-' LineWidth: 0.5000 Label: '' DisplayName: '' Show all properties
yyaxis right
hold on
boxA = boxplot(bothgrouped0hr.Turbinaria,bothgrouped0hr.Day,'Positions',[1, 14, 19, 26]);
boxB = boxplot(bothgrouped0hr.Duncan,bothgrouped0hr.Day,'Positions',[0, 13, 18, 26]);

Sign in to comment.

More Answers (0)

Tags

Asked:

on 23 May 2022

Commented:

on 24 May 2022

Community Treasure Hunt

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

Start Hunting!