Ask Your Question
1

How can multiple histograms be displayed on a single plot?

asked 2023-05-11 00:23:29 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-05-11 00:25:01 +0000

plato gravatar image

Multiple histograms can be displayed on a single plot by using the "hist" function in a loop or by using the "histogram" function in combination with the "hold on" command. Here is an example code in MATLAB:

% Create example data
data1 = randn(1000, 1);
data2 = randn(1000, 1) + 1;
data3 = randn(1000, 1) - 1;

% Plot multiple histograms using the hist function in a loop
figure;
hold on;
for i = 1:3
    subplot(3, 1, i);
    hist(eval(sprintf('data%d', i)));
end

% Plot multiple histograms using the histogram function and hold on command
figure;
hold on;
histogram(data1);
histogram(data2);
histogram(data3);

In the first example, we use a loop to iterate through each dataset and create a separate histogram for each. In the second example, we use the "histogram" function to plot each histogram on the same plot by calling it multiple times and using the "hold on" command to prevent the previous plot from being replaced.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-11 00:23:29 +0000

Seen: 18 times

Last updated: May 11 '23