2d line plot overlay boxplot

61 visualizaciones (últimos 30 días)
Richard
Richard el 12 de Mzo. de 2012
Is there a way of plotting a 2d line plot over a boxplot? the hold on command doesn't seem to apply for boxplots. If so, how would you account for the line plot having a different y axis to the boxplot?

Respuestas (1)

Oleg Komarov
Oleg Komarov el 12 de Mzo. de 2012
You are actually asking two nested questions.
Hold on applies:
data = rand(100,3);
boxplot(data)
hold on
line(1:3,[1,1,1])
To add a line on a different Y range:
data = rand(100,3);
boxplot(data)
set(gca,'box','off')
% Remove all other objects except the axes
h = copyobj(gca,gcf);
delete(allchild(h))
% Some features (you have to tweak the Y range manually)
set(h,'Color','none','XtickL','','YAxisLoc','right',...
'next','add','Ylim',[200,300])
% Add a line
plot(h,1:3,[220,240,260])

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by