how to plot three bar figure in one figure in matlab

To plot three bar figures in one figure in MATLAB, you can use the bar function multiple times. Here is an example code:

main.m
% Create sample data
categories = {'Category 1', 'Category 2', 'Category 3'};
data1 = [10 15 12];
data2 = [8 9 17];
data3 = [14 11 13];

% Create a figure
figure

% Plot the first bar figure
subplot(1,3,1)
bar(categories, data1)
title('Figure 1')

% Plot the second bar figure
subplot(1,3,2)
bar(categories, data2)
title('Figure 2')

% Plot the third bar figure
subplot(1,3,3)
bar(categories, data3)
title('Figure 3')
418 chars
24 lines

In this code, the subplot function is used to divide the figure into three parts, and then the bar function is called three times to plot the bar figures in each subplot. The title function is used to add titles to each subplot.

Make sure to adjust the categories and data variables according to your own data.

This will create one figure with three bar figures arranged horizontally.

related categories

gistlibby LogSnag