【问题标题】:How to display statistics as text in a graph?如何在图表中将统计数据显示为文本?
【发布时间】:2023-03-11 10:04:02
【问题描述】:

我在 matlab 中使用cdfplot 来绘制某些数量的经验 CDF。

[h,stats]=cdfplot(quantity)

现在stats 向我返回一个具有最小值、最大值、平均值等的结构。我希望这些值在图表中显示为文本。

我有很多类似的图表要绘制,不想手动绘制。

【问题讨论】:

  • 可以使用函数text

标签: matlab plot graph matlab-figure cdf


【解决方案1】:

要在绘图上添加文本,请使用 text 函数。这是一个关于一个情节的快速example

y = evrnd(0,3,100,1);
[h, stats] = cdfplot(y);
hold on
x = -20:0.1:10;
f = evcdf(x,0,3);
plot(x,f,'m')
legend('Empirical','Theoretical','Location','NW')
stat_type =  {'min: ';'max: ';'mean: ';'median: ';'std: '}; % make titles
stat_val = num2str(struct2array(stats).'); % convert stats to string
text(-15,0.7,stat_type) % <-- here
text(-11,0.7,stat_val) % <-- and here
hold off

这将给出:

您可以在循环中使用它来为所有图表执行此操作。

棘手的事情是定义在图表上放置文本的位置。在这里,我选择 (-15,0.7) 和 (-11,0.7) 作为我知道没有数据的固定点。你应该看看你的情节,并找到正确的地方。

【讨论】:

    最近更新 更多