【问题标题】:How to plot a histogram as a scatter plot in matlab?如何在matlab中将直方图绘制为散点图?
【发布时间】:2018-04-27 17:47:32
【问题描述】:

y 轴应该是频率(这是直方图部分),而 x 轴是用于绘制直方图的 xdata。基本上我需要的是一个直方图,但应该有点而不是条形图。

【问题讨论】:

  • 首先阅读help histogramhelp scatter的输出。

标签: matlab histogram scatter-plot


【解决方案1】:

我会使用histcounts 命令来做到这一点。这就像histogram 命令,但它不是绘制数据,而是返回每个 bin 中的数字和 bin 边缘。然后,您可以使用通用 plot 命令将其绘制为点。

x = randn(1,1000); %Generate some data to plot

figure(1); clf;
subplot(2,1,1); hold on;
h = histogram(x,'normalization','probability');
title('Plotted as a histogram');
ylabel('Frequency');

subplot(2,1,2); hold on;
[N, edges] = histcounts(x,'normalization','probability');
centers = (edges(1:end-1) + edges(2:end))./2; %histcounts gives the bin edges, but we want to plot the bin centers
plot(centers,N,'ko');
title('Plotted as points');
ylabel('Frequency');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-27
    • 1970-01-01
    • 2022-07-28
    • 2013-08-21
    • 1970-01-01
    • 2011-12-08
    相关资源
    最近更新 更多