2D-Histogram with log y and x ticks
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Alessandro Maria Laspina
el 20 de Jul. de 2022
Comentada: Steven Lord
el 20 de Jul. de 2022
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 comentarios
Respuesta aceptada
Steven Lord
el 20 de Jul. de 2022
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 comentarios
Steven Lord
el 20 de Jul. de 2022
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')
Más respuestas (0)
Ver también
Categorías
Más información sobre Colormaps en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!