2D graph + Colour. With meshed grid of variables X and Y
Afficher commentaires plus anciens
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 commentaires
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
le 21 Août 2012
Réponses (1)
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 commentaires
Laura
le 21 Août 2012
Sven
le 21 Août 2012
Laura, the "peaks" example is an example of how to make a "chessboard" picture like the one you were describing, but of course not with your data.
If you can get your data into a similar shape (ie, kind of like the chessboard you described) as the X and Y and Z matrices in the example, then the exact same type of picture can be made with your data.
I think the major problem is that your data is not in X, Y, Z chessboard-like matrices... But, it's not quite clear from your description what form your data is in.
Can you please describe very clearly what your X, Y, and Z are? Perhaps even paste them into a comment here.
For instance, when you call:
scatter(X, Y, pointsize, Z)
Do you truly get scattered values for X and Y, or are all your X and Y locations confined to a nice orderly grid?
If they are confined to a grid, then the task will be to rearrange your X, Y, Z vectors into grid form rather than vector form (we can help with that).
If your points are not confined to a grid, you will need to use interpolation to get gridded data. We can also help with that, but you need to show the kind of input you have. If we don't know your input, then we have to do things like use peaks() to make example input which may not be helpful if your real input is completely different.
Jürgen
le 22 Août 2012
Modifié(e) : Walter Roberson
le 23 Août 2012
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
le 23 Août 2012
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:
- Read all your data
- Organise your data into the right shape
- 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.
Catégories
En savoir plus sur Line Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!