3D Histogram with logarithmic frequency axis using hist3

9 views (last 30 days)
So I've been trying to make a 3D histogram with the logarithm of the frequencies on the z-axis (the color axis actually in this case) so that I can get a higher resolution look at the frequency differences between bins. At first I tried simply setting the z-axis to the log scale, but this did not yield the expected results. I then thought I had found the answer with the following code:
X = [gradVect errVect]; % the vectors are my data
N = hist3(X, 'Ctrs',{0:5:max(X(:,1)) 0:5:max(X(:,2))},'CdataMode','auto'); % Get frequency information
Nlog = log10(N); % The log of the frequencies
% Figure creation
figure; hold on
imagesc(Nlog)
xlabel("Error")
ylabel("Gradient")
title("Gradient vs. Error (Log)")
colorbar
caxis([0 4])
This, I believe, makes the desired histogram with one issue: my x and y axes information is incorrect. The axes become labeled with the bin numbers (so, for my data, 56 bins on the x-axis and 128 bins on the y-axis) rather than retaining the actual bin labels (0-275ish on the x-axis and 0-1200ish on the y-axis). Is there a way around this issue? I've been messing around with making this histogram for quite a while now, figured I'd seek help from people more adept at this than me! If there is a better way to achieve my goal here than what I'm doing, I'm also of course open to advice on that as well.
Code output (color axis is log base 10, axes are incorrect):
Another version, with correct axes ranges (though the axes are flipped, my apologies), but without the log scale:

Answers (1)

Walter Roberson
Walter Roberson on 13 Oct 2022
Use the imagesc(x,y,C) form of imagesc() where x and y are vectors of x coordinates of where to place the centers of vertices. Only the first and last entries in the vectors are paid attention to.
Remember that x corresponds to columns and y corresponds to rows

Categories

Find more on Data Distribution Plots in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!