MATLAB 畫圖
function createfigure1(X1, YMatrix1)
%CREATEFIGURE1(X1, YMATRIX1)
% X1: x 數據的矢量
% YMATRIX1: y 數據的矩陣
% eg: X1 = [1,2,3]
% YMatrix1 = [[1,2,3],[2,3,4]]
% 由 MATLAB 於 02-May-2020 13:14:38 自動生成
% 創建 figure
figure1 = figure('Name','測試','Color',[1 1 1]);
colormap(hot);
% 創建 axes
axes1 = axes('Parent',figure1,'Position',[0.1 0.1 0.8 0.8]);
hold(axes1,'on');
% 使用 plot 的矩陣輸入創建多行
plot1 = plot(X1,YMatrix1,'MarkerSize',3,'LineWidth',1,'Parent',axes1);
set(plot1(1),'DisplayName','方法1','Marker','+');
set(plot1(2),'DisplayName','方法2','Marker','>');
set(plot1(3),'DisplayName','方法3','Marker','*');
set(plot1(4),'DisplayName','方法4','Marker','hexagram');
set(plot1(5),'DisplayName','方法5','Marker','.');
% 創建 xlabel
xlabel('迭代次數','FontSize',8);
% 創建 ylabel
ylabel('準確率%','BackgroundColor',[1 1 1],'LineStyle','none',...
'EdgeColor',[0 0 0],...
'HorizontalAlignment','center',...
'FontSize',8);
% 取消以下行的註釋以保留座標軸的 X 範圍
xlim(axes1,[1 22]);
% 取消以下行的註釋以保留座標軸的 Y 範圍
ylim(axes1,[0.2 1]);
box(axes1,'on');
% 設置其餘座標軸屬性
set(axes1,'FontSize',8);
% 創建 legend
legend1 = legend(axes1,'show');
set(legend1,...
'Position',[0.6 0.2 0.1 0.1],...
'FontSize',8);
首先把上面的代碼保存,然後接下來調用:
x = linspace(0,1,10);
y = [x; x.*x; sin(x); cos(x); tan(x)].';
createfigure(x, y)