How to add an additional tick on y-axis for a combined boxplot and scatter plot?
6 views (last 30 days)
Show older comments
Hello all,
I've got 15 horizontal boxplots that reach up until y=1.6 and a scatter plot on the same figure, where the scatter plot are some x values at y=2 only.
I can see the boxplot ticks on the y-axis up until y=1.6. However, I cannot see a ytick on the y-axis at y=2. How can I add that?
**************************
My code until now is:
Ypos = [0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.5 1.6];
group_fordata = [repmat(Ypos(1),[size(x1),1]);
repmat(Ypos(2),[size(x2)],1); repmat(Ypos(3),[size(x3)],1);
repmat(Ypos(4),[size(x4)],1); repmat(Ypos(5),[size(x5)],1);
repmat(Ypos(6),[size(x6)],1); repmat(Ypos(7),[size(x7)],1);
repmat(Ypos(8),[size(x8)],1); repmat(Ypos(9),[size(x9)],1);
repmat(Ypos(10),[size(x10)],1); repmat(Ypos(11),[size(x11)],1);
repmat(Ypos(12),[size(x12)],1); repmat(Ypos(13),[size(x13)],1);
repmat(Ypos(14),[size(x14)],1); repmat(Ypos(15),[size(x15)],1)];
data = [x1;x2;x3;x4;x5;x6;x7;x8;x9;x1;x11;x12;x13;x14;x15]
figure
boxplot(data, group_fordata,'positions', Ypos,'orientation','horizontal')
hold on
scatter([0.4 0.6],[2.0 2.0],'g.')
ylim([0 2.1])
0 Comments
Accepted Answer
Chad Greene
on 2 Jun 2015
This solution's a little clunky, but it works:
% Create a label string for each Ypos:
for k = 1:numel(Ypos)
NewTickLabels{k} = sprintf('%0.1f',Ypos(k));
end
% Include 2.0:
NewTickLabels{k+1} = sprintf('%0.1f',2);
% Set tick values and labels:
set(gca,'YTick',[Ypos 2],'YTickLabel',NewTickLabels)
More Answers (1)
Chad Greene
on 29 May 2015
Edited: Chad Greene
on 29 May 2015
You can specify Ytick locations explicitly like this:
Ypos = [0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.5 1.6];
plot(rand(10,2),'bo')
ylim([0 2.1])
set(gca,'Ytick',[Ypos 1.7334 2])
3 Comments
See Also
Categories
Find more on Scatter Plots 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!