dr_rk
dr_rk

Reputation: 4565

Not able plot a line over a box-plot in MATLAB

I am drawing a box-plot so I use the following code in MATLAB. I am very new to matlab.

for k=1:N    % running through k categories in the plot 
  patch(...);   % The box 

  % now drawing the whiskers and percentiles 
  line(...); % the median
  line(..); % the 25th percentile 
  line(..); % the 75th percentile
  line(...); % the max
  line(..); % the min 
end

% THIS LINE ONLY IS DISPLAYED NOT THE BOX-PLOT, WHY?? 
% A poly-line passing median of each box 
plot([1:N]-0.5, Ys, '-Xr', 'LineWidth', 4, 'MarkerSize', 12);

The line drawn in the final statement only gets displayed, not the box-plot When I comment out the plot statement, then the box-plot is displayed.

But, how can I have them displayed one on top of the other?

Upvotes: 2

Views: 1524

Answers (1)

mathematician1975
mathematician1975

Reputation: 21351

I am not 100% sure if this will work as I have never used box plots, but to prevent multiple plots getting overwritten on a figure you usually use hold on command. Try adding the line hold on just before your final plot statement

Upvotes: 2

Related Questions