0
votes

I have 2 arrays of data x and y both are 22250-by-54, and I'm trying to use hist3 and imagesc to make density plots for each x(:,n) and y(:,n) pair where n = 1:54.

I'm using imagesc(values2) where:

values2 = hist3([x(:) y(:)],[round(max(x)) round(max(y)) ]);

to use as my argument to plot for each of the 54 x and y values to get a unique axis range and it works fine. However, when I place fixed integer values for values2 such as

values2 = hist3([x(:) y(:)],[50 50 ]);

the actual values for each of the 54 columns of x and y end up getting scaled to the [50 50] parameters or if I use [100 100] and it does not reflect the ACTUAL values for each x and y. How can I fix the axis x,y ranges and keep the actual values in the fixed axis range?

I have tried also using xlim and ylim in a separate call after the call to imagesc(values2) and this does not work either - it plots my data in a very small area and leaves lots of white space around the image area.

Thank you for your help!!

I have tried the "checked" response from the link below to get to where I am now: Scatter plot with density in Matlab

1
The x axis and y axis values or range of data are not equal. The x variable is wind speed and the y variable is temperature. Thank you,user2100039
An expected range for the x variable might be 0 to 30 (wind speed) and the expected y variable range for temperature to include all 54 cases might be -20 to +40. Thank you.user2100039
Hi - yes, that works in the same way that my current code works. The x and y axis ranges are changing with each new plot. This is not what I need. I want to compare the spread of the data with the same or fixed x and y axis range for each case above for n, where n = 1:54. Thanks!user2100039

1 Answers

0
votes

Using the answer you referenced you can write:

% some arbitrary data:
x = randi(30,30,54);
y = randi(61,30,54)-21;

% constant values for every n:
nbins = [round(range(y(:))) round(range(x(:)))]+1;
x_lim = [min(x(:)) max(x(:))];
y_lim = [min(y(:)) max(y(:))];

% plotting:
for n = 1:9
    [values2, centers] = hist3([x(:,n) y(:,n)],nbins);
    subplot(3,3,n) % this is just for compact demonstration
    h = imagesc(centers{:},values2.');
    title(num2str(n))
    xlim(x_lim) % keeping the x-axis limits constant
    ylim(y_lim) % keeping the y-axis limits constant
    axis xy
end

Note that you may get with areas for your plots, as in this example, if the data in x(:,n) or y(:,n) has a smaller range then y(:) and x(:,n).

which will give: imagesc hist