Schnigges
Schnigges

Reputation: 1326

Hist3 Plotting and Axes Range

I'm plotting a 3-D histogram with MATLAB and it's working pretty ok, except for the different axes ranges. I'd like them to be defined in a way, where equal value pairs lie on the bisecting line.

My code looks like this (more or less "stolen" from the hist3 MATLAB example):

[vec_voxel_ids, vec_dose_values_reference, vec_dose_values_control] = ...
    textread('_BOOSTINT_voxel_data.txt', '%u %u %u');
mat_dose_values = [vec_dose_values_reference, vec_dose_values_control];
hist3(mat_dose_values, [100, 100]);
xlabel('Dose Reference');
ylabel('Dose Control');
set(gcf, 'renderer', 'opengl');
set(get(gca,'child'), 'FaceColor', 'interp', 'CDataMode', 'auto');

This is how it looks: histogram

Upvotes: 1

Views: 9210

Answers (1)

horchler
horchler

Reputation: 18484

In order to reposition the bins to align their centers the ticks and also choose the range of the bin values you can use hist3's 'edges' option (similar to that in histc):

data = 500+5*randn(1e3,2);           % dummy data
d = 1;                               % width for x and y bins
x = 480:d:520;                       % range for x bins
y = x;                               % use same range for y bins, can be different
hist3(data, 'edges', {x-d/2,y-d/2}); % subtract half bin width to center bins
set(gcf, 'renderer', 'opengl');
set(get(gca,'child'), 'FaceColor', 'interp', 'CDataMode', 'auto');
view(2)
axis equal
axis([478 522 478 522])
grid minor
xlabel('x')
ylabel('y')

This example produces something like this: hist3 output

Note, that this is a re-binning of your data so your output may look slightly different compared to before. The bins have been shifted to align their centers and the histogram recalculated.

Upvotes: 4

Related Questions