How to plot 3D data as a 2D color plot (with axes representing parameter values)?

118 次查看(过去 30 天)
Using the imagesc function I can get a figure that looks like this:
However, the problem is the axes: the numbers simply list the index of each point in the matrix. I want each of those points in the matrix of output mapped to combinations of input values. As of now the axes are meaningless because they don't represent the phyiscal parameters I was using.
I found a few similar questions (e.g. here, and here), but I haven't quite figured it out. Is there no straightforward way to map each axis scale to a vector of parameter values? I tried changing the 'XData' property in the figure, but that just turned the whole image white, while the x-axis scale remained unchanged. I don't get it.
I'm looking into the pcolor function, and I think I could get that to work properly if necessary (although it looks much worse with default settings due to gridlines), but isn't there a way to get this to work with imagesc?
  1 个评论
convert_to_metric
convert_to_metric 2019-5-17
Hi Alexei,
If you are still looking for an answer, please provide your data and a description of what part of the data represents each axis.

请先登录,再进行评论。

采纳的回答

Alexei M
Alexei M 2019-7-7
编辑:Alexei M 2019-7-7
I figured it out. Using pcolor works like a charm.
The pcolor function 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, below. (I used a few extra commands for the color map, etc.) The key is that the axis label numbers adjust automatically to whatever my ranges of values in f and H are.

更多回答(1 个)

Josh
Josh 2019-5-21
I think I get what you're getting at.
When you use imagesc, you're plotting an image. Images have coordinates just like lines and patches. By default, the x and y values of the image will be its pixel coordinates. You can adjust this by setting the XData and YData properties of the image:
% Create a dummy image
im = bsxfun(@times, sin((0:99)/99*2*pi), cos((0:99)'/99*2*pi));
% Plot the image, and rescale so that the one corner of the image is
% plotted at [11, 10.7] and the opposite corner at [15, 18.2]:
imagesc(im, 'XData', [11, 15], 'YData', [10.7 18.2]);
When you set XData and YData of the axes, you're just adjusting what part of the graph is visible. If you're seeing all white, you're probably moving off into space somewhere where no part of the image is visible.

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by