2D-Histogram with log y and x ticks
조회 수: 5 (최근 30일)
이전 댓글 표시
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에서 Colormaps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!