如何在matlab中的双标图上加上标题?
How to put a title on a biplot in matlab?
我在 matlab 中创建了一个双标图
biplot = biplot(wcoeff(:,1:2),'Scores',score(:,1:2),'VarLabels',drugsFixed,'ObsLabels',cellLines,'MarkerSize',15)
看起来不错,但我想添加一个标题。将 'title'
添加到双标函数调用会导致错误。 'biplot' object 没有任何看起来可能包含标题句柄的 children。建议?
与许多绘图函数一样,我可以在调用 biplot
之后调用 title
为当前图形添加标题。
%% Biplot of Coefficients and Scores
% https://www.mathworks.com/help/stats/biplot.html#bt_y8xe-2
% Load the sample data.
% Copyright 2015 The MathWorks, Inc.
load carsmall
%%
% Define the variable matrix and delete the rows with missing values.
x = [Acceleration Displacement Horsepower MPG Weight];
x = x(all(~isnan(x),2),:);
%%
% Perform a principal component analysis of the data.
[coefs,score] = pca(zscore(x));
%%
% View the data and the original variables in the space of the first three
% principal components.
vbls = {'Accel','Disp','HP','MPG','Wgt'};
biplot(coefs(:,1:3),'scores',score(:,1:3),'varlabels',vbls);
%Add the title
title('My title');
如果正确的图不是当前图,您可以通过调用 figure(f)
更改当前图,其中 f
是您要添加标题的图句柄。
函数biplot
creates a bunch of line objects within the current axes, and only these name-value pairs are valid for the function input argument list. The line objects are children of the axes object, and it's the axes object that contains the 'Title'
property。如果要添加标题,则必须使用单独的命令来完成,例如以下命令之一:
title('Biplot title');
%Or...
hAxes = gca;
hAxes.Title.String = 'Biplot title';
我认为 >>title 以及 >>xlabel 和 >>ylabel 必须在实际情节之外调用。我假设以下代码将在您的 m-file:
中的某处
biplot(*All of the parameters go in here*)
title('This is a title.')
xlabel('This labels the x-axis.')
ylabel('This labels the y-axis.')
Here 是 MATLAB 标题文档,如果你需要的话。我发现 MathWorks 的文档非常详尽。
我在 matlab 中创建了一个双标图
biplot = biplot(wcoeff(:,1:2),'Scores',score(:,1:2),'VarLabels',drugsFixed,'ObsLabels',cellLines,'MarkerSize',15)
看起来不错,但我想添加一个标题。将 'title'
添加到双标函数调用会导致错误。 'biplot' object 没有任何看起来可能包含标题句柄的 children。建议?
与许多绘图函数一样,我可以在调用 biplot
之后调用 title
为当前图形添加标题。
%% Biplot of Coefficients and Scores
% https://www.mathworks.com/help/stats/biplot.html#bt_y8xe-2
% Load the sample data.
% Copyright 2015 The MathWorks, Inc.
load carsmall
%%
% Define the variable matrix and delete the rows with missing values.
x = [Acceleration Displacement Horsepower MPG Weight];
x = x(all(~isnan(x),2),:);
%%
% Perform a principal component analysis of the data.
[coefs,score] = pca(zscore(x));
%%
% View the data and the original variables in the space of the first three
% principal components.
vbls = {'Accel','Disp','HP','MPG','Wgt'};
biplot(coefs(:,1:3),'scores',score(:,1:3),'varlabels',vbls);
%Add the title
title('My title');
如果正确的图不是当前图,您可以通过调用 figure(f)
更改当前图,其中 f
是您要添加标题的图句柄。
函数biplot
creates a bunch of line objects within the current axes, and only these name-value pairs are valid for the function input argument list. The line objects are children of the axes object, and it's the axes object that contains the 'Title'
property。如果要添加标题,则必须使用单独的命令来完成,例如以下命令之一:
title('Biplot title');
%Or...
hAxes = gca;
hAxes.Title.String = 'Biplot title';
我认为 >>title 以及 >>xlabel 和 >>ylabel 必须在实际情节之外调用。我假设以下代码将在您的 m-file:
中的某处biplot(*All of the parameters go in here*)
title('This is a title.')
xlabel('This labels the x-axis.')
ylabel('This labels the y-axis.')
Here 是 MATLAB 标题文档,如果你需要的话。我发现 MathWorks 的文档非常详尽。