【问题标题】:plotting text from string vector or table on the point plot in MATLAB在MATLAB中的点图上绘制字符串向量或表格中的文本
【发布时间】:2018-09-19 10:47:22
【问题描述】:

我在 MATLAB 中通过gscatter 绘制。速度与年份的关系图。现在在我的情况下还有另一个列向量或表,其中包含相应的绘图点字符串。该表是int 变量。

我想显示图表上绘制点的 int 变量的相应文本。谁能帮帮我?

这是我数据的link

这是我的代码:

T = readtable('Data_Serial.xlsx');

int = T.Int;
BW = T.Band;
type = T.Type;
year = T.Year;
g = {type};

labels = cellstr(int); 

% Plot Data
f = figure;
box on;
gscatter(year,BW,g,'rkgb','o*',8,'on','Year','Speed')
hold on;
text(year(:,1), BW(:,2), labels, 'VerticalAlignment','bottom', ...
                         'HorizontalAlignment','right')

显示如下错误:

>> Data_Serial
Index exceeds matrix dimensions.

Error in Data_Serial (line 16)
text(year(:,1), BW(:,2), labels, 'VerticalAlignment','bottom', ...

【问题讨论】:

  • @gehbiszumeis 感谢您的回答。我看到的那个例子。在该示例中,他们使用labels = cellstr( num2str([1:10]') ); 将行号转换为字符串。就我而言,我将字符串表存储在int 中。所以我把 labels = cellstr(int); 设置为我正在使用 scatter 函数,它使我能够根据另一个变量进行绘图。但是那个标签仍然不起作用。我已经更新了我的问题中的代码。

标签: matlab plot text scatter-plot


【解决方案1】:

您应该从 BW 中的 1 开始索引。

这应该显示带有文本标签的图

text(year(:,1), BW(:,1), labels, 'VerticalAlignment','bottom', ...
                         'HorizontalAlignment','right')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-17
    • 1970-01-01
    • 2013-07-23
    • 2011-07-03
    • 2023-03-25
    • 2016-07-07
    • 2014-07-02
    • 1970-01-01
    相关资源
    最近更新 更多