【发布时间】:2018-04-27 17:47:32
【问题描述】:
y 轴应该是频率(这是直方图部分),而 x 轴是用于绘制直方图的 xdata。基本上我需要的是一个直方图,但应该有点而不是条形图。
【问题讨论】:
-
首先阅读
help histogram和help scatter的输出。
标签: matlab histogram scatter-plot
y 轴应该是频率(这是直方图部分),而 x 轴是用于绘制直方图的 xdata。基本上我需要的是一个直方图,但应该有点而不是条形图。
【问题讨论】:
help histogram和help scatter的输出。
标签: matlab histogram scatter-plot
我会使用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');
【讨论】: