How can I make a boxplot match at 0 with another plot?

3 ビュー (過去 30 日間)
Isaac Elías
Isaac Elías 2023 年 1 月 14 日
コメント済み: Isaac Elías 2023 年 2 月 21 日
Hi
I'm having trouble making a boxplot match at the origin with another plot (colored lines). The first plot works just fine, but as the boxplot works with a categorical x axis, it shifts away from the actual origin and I just cant make it match back into place.
Can anyone help me, please.
  1 件のコメント
the cyclist
the cyclist 2023 年 1 月 14 日
編集済み: the cyclist 2023 年 1 月 14 日
Here are a few things that would make it easier to help you. If you can do some or all of these things, you might have a better chance at getting a solution:
  • Upload your data
  • Upload your code
  • Make a figure with just two panels: One that is how you want it, and one that is not how you want it
  • Explain what you mean by "it shifts away from the actual origin". I'm not sure what "it" is (e.g. are you talking about the boxes, or the lines, or something else?). I don't know what the "actual origin" means.
Mainly, I don't know what exactly is supposed to "match at the origin". And even if I did understand that, it's probably not possible to give advice about how to fix that, without seeing your code, your data, or both.

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

回答 (1 件)

Constantino Carlos Reyes-Aldasoro
Constantino Carlos Reyes-Aldasoro 2023 年 1 月 16 日
A workaround to solve your problem is to call the boxplots with zero values in between your actual data. E.g.
plot([1 2 3 4 5 6 7],[ 9 8 7 6 5 4 3 ],'-o')
hold on
x1 = rand(50,1);
x2 = ones(50,1);
boxplot([0 ; 5*x1 ; 0 ;0; x1*4;0;x1*8],[1; 2*x2; 3 ;4; 5*x2;6;7*x2])
In this way, the boxplots are located exactly at the same location as the other plot.
  3 件のコメント
Constantino Carlos Reyes-Aldasoro
Constantino Carlos Reyes-Aldasoro 2023 年 1 月 16 日
that is better!
Isaac Elías
Isaac Elías 2023 年 2 月 21 日
Thak you both!
This advice helped to make the boxes match my actual data for times above 0. Although I could´nt make the first box appear at time zero of the line plot (wich apparently, is not possible, as boxplot works with categorical data).

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

Community Treasure Hunt

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

Start Hunting!

Translated by