2D graph + Colour. With meshed grid of variables X and Y

10 次查看(过去 30 天)
I have a file containing the variables X Y and Z. Id like to plot a graph, on which theres a meshed grid of the variables X and Y (the grid lines should appear for every value of X and Y) and then plot the graph with the corresponding color of the variable Z, this variable depends of x and y.
So far i've tried the function scatter and came across a plotted graph, but the problem i have, is that my gridlines appear every 5 values of X and Y, instead of appearing for every value of X (from 0 to 23 by steps of 1) and Y (from 2 to 30, and by steps of 0.5). And with this function i get circles as markers where id like to get tiny rectangles as markers.
pointsize = 10;
scatter(X, Y, pointsize, Z);axis([00 23 2 30 ]);grid on;hold on;
The idea I have in mind of the plotted graph is like a chessboard, on which every square(in this case rectangle) should have a color matching the value of Z.
Id also would like to know how can be set the min and max values for Z color wise (if Z goes from 0.5 to 1).
Thanks !!
  2 个评论
Jürgen
Jürgen 2012-8-21
编辑:Jürgen 2012-8-21
Hi, it's a bit confusing: if you work with a grid of X and Y values , the Z values are actually the values at the grid points, not inside the squares, if you want to have each square in a color corresponding to the Z values, you probably need to estimated the Z value in the middle of the square and relate that one to the colors.
on the otherhand if you want to create a surface take a look at the surf command
Laura
Laura 2012-8-21
Looks like you were right Jürgen,
with the function peaks i think i get an estimation for my variables, the problem i have with surface is that the variable which i am aplying this has to be a matrix, not an escalar as it is on my code..
thanks for your quick response !!

请先登录,再进行评论。

回答(1 个)

Sven
Sven 2012-8-21
编辑:Sven 2012-8-21
Hi Laura, try this:
% Make your data (you've probably got your own X,Y,Z)
[X,Y,Z] = peaks;
% Show your data
figure, surf(X,Y,Z)
view(2) % This will give you a top-down view
The method above actually makes a 3D view (and then changes the camera angle to look at it top-down).
You can then set the colour range as follows:
colorbar % Just so you can see the colour scale
caxis([-2 3]) % Set new min/max limits on the colour scale
  5 个评论
Jürgen
Jürgen 2012-8-22
编辑:Walter Roberson 2012-8-23
Hey,
I think what Sven proposed is
X= frecu; % Column Array representing the frequencies
Y= hora; % Column Array representing time
Z=corr;% values of Z at (X,Y)
[Xgrid,Ygrid] = meshgrid(X,Y);
Zgrid=zeros(size(Xgrid);
% then fill Zgrid with the values of Z that you want at X en Y
% Zgrid(indexX, IndexY) = Zvalues
FigHandle=figure('Name','YourFigureName');
title(gca,'YourTitleName');
hold on
plot(MidCompAngleInDegCompNb(11:36,1),EstimatedSpeed,'^r');
surf(Xgrid,Ygrid,Zgrid)
view(2) % This will give you a top-down view
an the other hand if you use image see teh help file
'image(x,y,C), where x and y are two-element vectors, specifies the range of the x- and y-axis labels, but produces the same image as image(C).
'
maybe this helped,
Sven
Sven 2012-8-23
Hi Laura,
I think that using image() inside a loop (basically making many many plots of a single scalar pixel) is usually a bad idea. Generally, you should:
  1. Read all your data
  2. Organise your data into the right shape
  3. Display your data
I think that you misunderstand what we mean by shape because you are only plotting one scalar value at a time. Your final code will have one single call to image() or surf(), and the size of your X, Y, and Z data will be M-by-N (where M and N will be numbers much bigger than 1-by-1).
Please show us the data you are reading. Either upload the file somewhere, or at least copy/paste in the first few (~50) lines.

请先登录,再进行评论。

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by