histogram2 configuration for colorbar and frenquency of cells

14 ビュー (過去 30 日間)
Felipe Aranda Delgado
Felipe Aranda Delgado 2019 年 12 月 4 日
コメント済み: breathi 2019 年 12 月 9 日
Hello, how can i do this in matlab? Put the frenquency and the colours as the colorbar.

採用された回答

breathi
breathi 2019 年 12 月 5 日
Hi,
try somethings like this when using histogram2
% Your data
data.X = randn(1,10000).*2+10;
data.Y = randn(1,10000)+6;
data.XEdges = 0:1:20;
data.YEdges = 0:12;
% Data counting number of occurencies
h=histogram2(data.X,data.Y ,data.XEdges, data.YEdges,'FaceColor','flat','EdgeColor','none');
% Modifying colormap with a bit of white at the end
cb = colorbar;
p=colormap('jet');
p(1:7,1:3) = [linspace(1,0,7)',linspace(1,0,7)',ones(7,1)];
colormap(p);
cb.Label.String = 'ColorBarString';
% Some labels
xlabel('X')
ylabel('Y')
zlabel('Enumeration of occurencies')
% create text labels from histcounts2
N = histcounts2(data.X,data.Y,data.XEdges,data.YEdges);
for xi=1:size(N,1)
for yi=1:size(N,2)
if N(xi,yi) > 0
text(mean(data.XEdges(xi:xi+1)), mean(data.YEdges(yi:yi+1)), num2str(N(xi,yi)), 'HorizontalAlignment', 'center', 'VerticalAlignment', 'middle');
end
end
end
h.FaceAlpha = .5;
% plot some curves at bottom
hold on,
plot(1:20,1:20)
% change view to 2D from below (to see texts & plots)
view(0,-90)
% reverse YDir
h.Parent.YDir = 'reverse';
Alternatively you could use other plot commands like bar3, ...
This should help you going where you want.
  2 件のコメント
Felipe Aranda Delgado
Felipe Aranda Delgado 2019 年 12 月 6 日
Hey! it works. But i want a blur effect on the edge of the bins . Do you know how to do that?
breathi
breathi 2019 年 12 月 9 日
I'm not sure, you can try using something like this for a histogram2:
h.EdgeColor = 'k'
h.LineWidth = 4
h.EdgeAlpha = 0.1
But then the colors form the colorbar are obviously not applied as the borders. I could imagine that the colors are plotted by hand and the colorbar is just a dummy then.
But maybe someone else can help out here.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by