【问题标题】:How to put a title on a biplot in matlab?如何在matlab中的biplot上放置标题?
【发布时间】:2017-07-20 17:20:48
【问题描述】:

我在 matlab 中创建了一个双标图

biplot = biplot(wcoeff(:,1:2),'Scores',score(:,1:2),'VarLabels',drugsFixed,'ObsLabels',cellLines,'MarkerSize',15)

看起来不错,但我想添加一个标题。将'title' 添加到biplot 函数调用会导致错误。 'biplot' 对象没有任何看起来可能包含标题句柄的子对象。有什么建议吗?

【问题讨论】:

  • 您是否尝试过使用title 功能?它适用于双标图示例。

标签: matlab pca


【解决方案1】:

与许多绘图功能一样,我可以在调用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 是您要添加标题的图句柄。

【讨论】:

    【解决方案2】:

    函数biplot在当前坐标区中创建了一堆线对象,只有these name-value pairs对函数输入参数列表有效。线对象是坐标区对象的子对象,它是包含'Title' property 的坐标区对象。如果要添加标题,则必须使用单独的命令来完成,例如以下命令之一:

    title('Biplot title');
    %Or...
    hAxes = gca;
    hAxes.Title.String = 'Biplot title';
    

    【讨论】:

    • 我喜欢你的回答解决了为什么使用单独的命令修改标题属性。
    【解决方案3】:

    我相信 >>title 以及 >>xlabel 和 >>ylabel 必须在实际情节之外调用。我假设以下代码将在您的 m 文件中的某处:

    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 的文档非常详尽。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-14
      相关资源
      最近更新 更多