How can I add a plot over a boxplot (same axis)?

16 ビュー (過去 30 日間)
Blabla
Blabla 2018 年 5 月 5 日
コメント済み: Blabla 2018 年 5 月 6 日
I have a figure with 96 boxplots that resulted from 10000 simulated forecasts. I need to plot the real observation dataset over it, but the 'hold on' command do not work. It simply plots the boxplot. My script is
figure
boxplot(xx',months,'PlotStyle','compact')
hold on
plot(months, si, 'r','LineWidth', 2)
both xx' and si have the same dimensions. xx' is 10000x97 and si 1x97.
Does someone have any idea how to include both plots in one figure??

採用された回答

dpb
dpb 2018 年 5 月 6 日
編集済み: dpb 2018 年 5 月 6 日
Works ok here to plot() data on top of a boxplot; didn't use grouping variables though so the x-axes values are 1:N where N is the number of variables. I would presume that's what happens with a grouping variable but don't have anything handy to -- oh, wait a minute, ISTR one of the examples does use grouping -- yes, indeed. OK, starting from having data in the example,
figure
boxplot(MPG,Origin) % sample boxplot with grouping
hAx=gca; % retrieve the axes handle
xtk=hAx.XTick; % and the xtick values to plot() at...
hold on
hL=plot(xtk,rand(size(xtk))*50,'k-*'); % draw a line on top...
Seems to work just fine; I'm guessing you're not plotting at the correct x,y locations given the axis limits; particularly the x-axis being ordinal so XTick-->1:N, not the value of the grouping variable.
  3 件のコメント
dpb
dpb 2018 年 5 月 6 日
Thunk it wood... :) Was it the x positions that was the problem or something else before (just curious)?
Blabla
Blabla 2018 年 5 月 6 日
The x position. I knew I had to redefine the axis but I had not idea how to write that. Thanks again :)

サインインしてコメントする。

その他の回答 (0 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by