如何在matlab中将直方图绘制为散点图?

时间:2018-04-27 17:47:33

标签: matlab histogram scatter-plot

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

1 个答案:

答案 0 :(得分: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');