2D-Histogram with log y and x ticks
6 ビュー (過去 30 日間)
古いコメントを表示
Alessandro Maria Laspina
2022 年 7 月 20 日
コメント済み: Steven Lord
2022 年 7 月 20 日
Hello,
set(gca,'Yscale','log')
set(gca,'Xscale','log')
The issue is that this makes the grids unequally spaced. I want the grids to have the same spacing. Also, I want to apply the following bin edges:
edges=[0 1:1:6 1e1 1e2 1e3 1e4 1e7];
The solution that I have now is the following:
edges=[0 1:1:6 1e1 1e2 1e3 1e4 1e7];
data = rand(100,2);
hh3 = hist3(data, 'Nbins',[1 1]*60);
image(flipud(hh3))
ax = gca;
xt = ax.XTick;
yt = ax.YTick;
ax.XTickLabel = xt*10;
set(ax, 'YTick',[0 yt], 'YTickLabel', [flip([0 yt])]*10)
colorbar
set(gca,'Yscale','log')
set(gca,'Xscale','log')
This also creates the issue of whitespace outside the range of values available. Additionally, I would also like to use a discrete color bar with discrete color values.
Any suggestions?
0 件のコメント
採用された回答
Steven Lord
2022 年 7 月 20 日
Instead of using hist3 I recommend you use histogram2.
edges=2.^(-8:0) % Set the lower limit to be whatever will cover your data
data = rand(100,2);
histogram2(data(:, 1), data(:, 2), ... % X and Y data
edges, edges, ... % X and Y edges
'DisplayStyle', 'tile')
set(gca, 'XScale', 'log', 'YScale', 'log')
2 件のコメント
Steven Lord
2022 年 7 月 20 日
If you want the bins that have no data to be displayed, specify ShowEmptyBins. The default is false, meaning not to show those empty bins.
edges=2.^(-8:0); % Set the lower limit to be whatever will cover your data
data = rand(100,2);
histogram2(data(:, 1), data(:, 2), ... % X and Y data
edges, edges, ... % X and Y edges
'DisplayStyle', 'tile', ...
'ShowEmptyBins', true)
set(gca, 'XScale', 'log', 'YScale', 'log')
colorbar
With only 100 data points in this sample data set, many of the bins are empty. If you used a million points instead:
figure
data = rand(1e6,2);
histogram2(data(:, 1), data(:, 2), ... % X and Y data
edges, edges, ... % X and Y edges
'DisplayStyle', 'tile', ...
'ShowEmptyBins', true)
set(gca, 'XScale', 'log', 'YScale', 'log')
colorbar
Or displayed the histogram2 using its default DisplayStyle, you can see that the bins associated with smaller X and/or Y values really don't contain much data.
figure
histogram2(data(:, 1), data(:, 2), ... % X and Y data
edges, edges, ... % X and Y edges
'ShowEmptyBins', true)
set(gca, 'XScale', 'log', 'YScale', 'log')
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Distribution Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!