I'm experimenting with using imagesc
function because I need to make a 2D color plot of 3D data, where the color indicates the strength of signal output for each combination of 2 inputs, and the x and y axes should represent the input parameters. I looked at this question, which is similar:
How to change image axis labels
The problem is that I don't know beforehand the range of values that my input parameters will have, and they're not necessarily "nice", "round" numbers either, that can be spaced by 10 or some other integer. Worse, depending on the test that I do, my data might have the order of inputs inverted. For instance, if I manually set the x-axis to go from low to high values (as is standard), it may actually be backward from how my data actually is, if my parameter values were being input from high to low.
example of my output image using imagesc function
I included an example of the image that I got so far. The y-axis was left as default, which simply shows that I have over 180 rows in the matrix of my output signal. I changed the x-axis by using linspace
to correspond to the range of input parameters from lowest to highest value. However, the image should be flipped horizontally, because I know that the yellow spot on the right should correspond to low values on the x-axis--that is, it should be on the left side.
So I need to make this happen automatically, that the strength of my output signal gets correctly matched to the combination of 2 input parameters (which are shown on the x & y axes), and the output for each combination is represented by a color on a color scale.
Is there just no way to do this using imagesc
? Do I have to use the pcolor
function instead? Or is there some other approach?
Using the pcolor
function, I got what I wanted. It directly translates the intuitive relationship between (matrix) variables into a graphic image with the correct axis scales. I had 3 variables; let's call them f
, H
, and Z
. The point was to make a color plot with a value from Z
that corresponds to each unique f
,H
value pair, similar to an x,y coordinate. So, I made f
and H
into matrices (with same dimensions), where f
has all the columns be copies of one column vector, and H
has all the rows be copies of one row vector. (Z
was already a matrix, with same dimensions.) That way, if I pick an i,j element from both f
and H
matrices, I get a unique f
,H
pair and can map it to an i,j element in Z
. Then simply plot using:
pcolor(f,H,Z)
And I get an image like this (with a few additional commands): f,H color plot example
The axis number labels adjust automatically to match the f
and H
values.