Is it possible to draw a Min Max line plot ("Boxplot without box")?

13 views (last 30 days)
Hi everybody,
I am asking a simple and apparently silly question but I cannot find an answer. Is it possible to plot a Max Min line plot, a sort of box plot without the box, in Matlab?
Thanks in advance.
MD

Answers (3)

arushi
arushi on 20 Aug 2024
Hi Maja,
Here is an example for the query to plot a Max Min line plot, a sort of box plot without the box :
% Sample data: each column represents a category or set
data = [1, 2, 3, 4, 5;
2, 3, 4, 5, 6;
1.5, 2.5, 3.5, 4.5, 5.5;
0.5, 1.5, 2.5, 3.5, 4.5];
% Calculate the max and min values for each column
maxValues = max(data);
minValues = min(data);
% Number of categories
numCategories = size(data, 2);
% X-axis positions for the categories
x = 1:numCategories;
% Plot the max-min lines
figure;
hold on;
for i = 1:numCategories
plot([x(i), x(i)], [minValues(i), maxValues(i)], 'k-', 'LineWidth', 2);
end
% Optionally, add markers for max and min
plot(x, maxValues, 'ro', 'MarkerFaceColor', 'r');
plot(x, minValues, 'bo', 'MarkerFaceColor', 'b');
% Customize the plot
xlabel('Category');
ylabel('Value');
title('Max-Min Line Plot');
grid on;
hold off;
Hope this helps.

Shubham
Shubham on 20 Aug 2024
Hi Maja,
In MATLAB, you can create a "Max-Min" line plot, which resembles a box plot without the boxes, by plotting the maximum and minimum values as lines. Here's a step-by-step guide to achieve this:
  1. Prepare Your Data: Assume you have a matrix data where each column represents a different group and each row represents an observation.
  2. Calculate Statistics: Compute the minimum and maximum values for each group.
  3. Plot the Max-Min Lines: Use the plot function to create the lines for the maximum and minimum values.
Here is an example code snippet to illustrate this:
% Sample data: each column is a different group
data = rand(10, 3); % 10 observations for 3 groups
% Calculate min and max for each group
minValues = min(data);
maxValues = max(data);
% Number of groups
numGroups = size(data, 2);
% Create a new figure
figure;
% Plot max and min lines
hold on;
for i = 1:numGroups
% Plot line from min to max for each group
plot([i, i], [minValues(i), maxValues(i)], 'k-', 'LineWidth', 2);
end
% Customize the plot
xlim([0.5, numGroups + 0.5]);
xticks(1:numGroups);
xlabel('Group');
ylabel('Value');
title('Max-Min Line Plot');
grid on;
hold off;
This approach will give you a simple Max-Min line plot for your data. You can further customize the appearance by adjusting line styles, colors, and markers as needed.

Aneela
Aneela on 20 Aug 2024
Edited: Aneela on 21 Aug 2024
Hi Maja,
It is possible to draw a Min-Max plot, a box plot without the box.
I executed the code below in R2024a, which uses "errorbar" function to plot the Max-Min Line plot:
% Sample data
data = rand(100, 5); % 100 samples for 5 different groups
% Calculate minimum and maximum for each group
minValues = min(data);
maxValues = max(data);
% Calculate the mean for each group
meanValues = mean(data);
% Calculate the error
lowerError = meanValues - minValues;
upperError = maxValues - meanValues;
% Define x positions for each group
x = 1:size(data, 2);
% Plot the Max-Min lines using error bars
figure;
errorbar(x, meanValues, lowerError, upperError, 'k', 'LineStyle', 'none', 'LineWidth', 2);
xlim([0.5, length(x) + 0.5]);
xticks(x);
xlabel('Group');
ylabel('Value');
title('Max-Min Line Plot using Error Bars');
grid on;

Community Treasure Hunt

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

Start Hunting!