Creating a Combined Bar Graph in MATLAB

Creating a Combined Bar Graph in MATLAB

Creating a Combined Bar Graph in MATLAB
Creating a Combined Bar Graph in MATLAB
Creating a Combined Bar Graph in MATLAB

Creating a Bar Graph

Combined Graph

Author: Li Zhi, Eighth Galaxy

Contact Email: [email protected]

Precipitation Bar Chart
clear;clc
% Precipitation Bar Chart
subplot(2,1,1)% Group chart 2 rows 1 column first chart
x1=xlsread('Temperature_Precipitation.xlsx','Date','A2:A366');% Read x-axis

y1=xlsread('Temperature_Precipitation.xlsx','Precipitation','A2:A366');% Read y-axis
bar(x1,y1,1)% Draw bar chart
ylabel('mm')% y-axis label
axis([0,365,-1,10]) % Set axis size
text(20,8,'Test','fontname','Times New Roman','fontsize',12,'fontweight','bold')% Set title parameters
set(gca,'XTick',[ 32 60 91 121 152 182 213 244 274 305 335]) 
set(gca,'xticklabel',{'02-01','03-01','04-01','05-01','06-01','07-01','08-01','09-01','10-01','11-01','12-01'})% x-axis ticks
% The above two lines, the second line adds a description to the first line
set(subplot(2,1,1),'fontname','Times New Roman','fontsize',13,'fontweight','bold','LineWidth',5)% Set chart frame parameters
Profile Chart
% Profile Chart
subplot(2,1,2)
x    = xlsread('Temperature_Precipitation.xlsx','Date','A2:A366');% Read x-axis
xmax = max(x);
xmin = min(x);
y    = [30 60 120 160 180];% Soil depth, i.e., y-axis

ymax = max(y);
ymin = min(y);
z    = xlsread('Temperature_Precipitation.xlsx','Temperature','A2:E366');% Values at each (x,y) point
C=z';
N = 365; % Number of data points per dimension
[X,Y]=meshgrid(linspace(xmin,xmax,N),linspace(ymin,ymax,N));% Grid x,y two-dimensional space
Z =griddata(x,y,C,X,Y,'linear');% Interpolation method to expand data, using 'linear' method
contourf(X,Y,Z,N, 'LineColor','none');% Set contour plot
colormap('jet')% Set color map
colorbar('fontname','Times New Roman','FontSize',15,'LineWidth',5)% Set color bar parameters
hold on 
ylabel('cm') % y-axis label description
set(gca,'XTick',[32 60 91 121 152 182 213 244 274 305 335]) 
set(gca,'xticklabel',{'02-01','03-01','04-01','05-01','06-01','07-01','08-01','09-01','10-01','11-01','12-01','fontname','Times New Roman','fontsize',20,'fontweight','bold'})% x-axis ticks and parameters
set(gca,'YTick',[30 60 120 160 180]) 
set(gca,'yticklabel',{'30', '60', '120', '160', '180'})% y-axis ticks and parameters
set(subplot(2,1,2),'fontname','Times New Roman','fontsize',13,'fontweight','bold','LineWidth',5)% Set chart frame parameters
Set Color Range for Scatter Markers

Step 1, Open figure1 window, click the blue arrow to edit the drawing

Creating a Combined Bar Graph in MATLAB

Step 2, Click Tools, check View Layout Grid

Creating a Combined Bar Graph in MATLAB

Step 3, Click on the profile chart border, hold the left mouse button to move the image when the cursor is a cross arrow, and stretch the image when it is a straight arrow

Creating a Combined Bar Graph in MATLAB

Step 4, Click File, select Export File

Creating a Combined Bar Graph in MATLAB

Step 5, Click Render, change the resolution to 600, and finally click Export

Creating a Combined Bar Graph in MATLAB

Reference Image

Creating a Combined Bar Graph in MATLAB

Complete Code
clear;clc
% Precipitation Bar Chart
subplot(2,1,1)% Group chart 2 rows 1 column first chart
x1=xlsread('Temperature_Precipitation.xlsx','Date','A2:A366');% Read x-axis

y1=xlsread('Temperature_Precipitation.xlsx','Precipitation','A2:A366');% Read y-axis
bar(x1,y1,1)% Draw bar chart
ylabel('mm')% y-axis label
axis([0,365,-1,10]) % Set axis size
text(20,8,'Test','fontname','Times New Roman','fontsize',12,'fontweight','bold')% Set title parameters
set(gca,'XTick',[ 32 60 91 121 152 182 213 244 274 305 335]) 
set(gca,'xticklabel',{'02-01','03-01','04-01','05-01','06-01','07-01','08-01','09-01','10-01','11-01','12-01'})% x-axis ticks
% The above two lines, the second line adds a description to the first line
set(subplot(2,1,1),'fontname','Times New Roman','fontsize',13,'fontweight','bold','LineWidth',5)% Set chart frame parameters

% Profile Chart
subplot(2,1,2)
x    = xlsread('Temperature_Precipitation.xlsx','Date','A2:A366');% Read x-axis
xmax = max(x);
xmin = min(x);
y    = [30 60 120 160 180];% Soil depth, i.e., y-axis

ymax = max(y);
ymin = min(y);
z    = xlsread('Temperature_Precipitation.xlsx','Temperature','A2:E366');% Values at each (x,y) point
C=z';
N = 365; % Number of data points per dimension
[X,Y]=meshgrid(linspace(xmin,xmax,N),linspace(ymin,ymax,N));% Grid x,y two-dimensional space
Z =griddata(x,y,C,X,Y,'linear');% Interpolation method to expand data, using 'linear' method
contourf(X,Y,Z,N, 'LineColor','none');% Set contour plot
colormap('jet')% Set color map
colorbar('fontname','Times New Roman','FontSize',15,'LineWidth',5)% Set color bar parameters
hold on 
ylabel('cm') % y-axis label description
set(gca,'XTick',[32 60 91 121 152 182 213 244 274 305 335]) 
set(gca,'xticklabel',{'02-01','03-01','04-01','05-01','06-01','07-01','08-01','09-01','10-01','11-01','12-01','fontname','Times New Roman','fontsize',20,'fontweight','bold'})% x-axis ticks and parameters
set(gca,'YTick',[30 60 120 160 180]) 
set(gca,'yticklabel',{'30', '60', '120', '160', '180'})% y-axis ticks and parameters
set(subplot(2,1,2),'fontname','Times New Roman','fontsize',13,'fontweight','bold','LineWidth',5)% Set chart frame parameters

Please do not reply to Eighth Galaxy other words

ShareCollectLikeLook

Editor: myp

Leave a Comment