I am plotting a map between x,y and density. x and y are distances. Is there any other method apart from scatterplot to plot it. I want the density to be shown in colorbar. I have been doing the following:
scatter(x(1:end-1), y(1:end-1), 5, g);
colorbar('eastoutside');
caxis([12 max(g)]);
Use surf(x,y,z), in which x, and y are your distances and z is density.
Related
I'm tiring to plot contour map like picture is following below , i can plot the contour, but problem is with shadow area on contour . actually i have 4 vector data [x,y,z,k]. x,y area coordinates and z , k are levels .
my code:
sample=xlsread('sample.xlsx');
x=(sample(:,1));
y=(sample(:,2));
z=(sample(:,3));
k=sample(:,4);
N=50;
[X,Y]=meshgrid(linspace(min(x)-0.2, max(x)+0.2, N), linspace(min(y)-0.2, max(y)+0.2, N));
F = scatteredInterpolant(x, y, z);
FF=scatteredInterpolant(x, y, k);
Z= F(X,Y);
ZZ=FF(X,Y);
contour(X,Y,Z,'ShowText','on') %main contour
hold on
???? shadow???
How should do this ?? thanks
If you have the X-Y points of the "shadow area", you can use the fill command (documentation)
fill(X_Area,Y_Area,'b')
if the function F is available it is easy to draw surf plot i.e.
x=1:0.1:4;
y=1:0.1:4;
[X,Y]=meshgrid(x,y);
Z=sin(X).^2+cos(Y).^2;
surf(X,Y,Z);
view(2) ;
in my case I calculated F function using least square:
for example I have x and y vectors
x = [0 9.8312 77.1256 117.9810 99.9979];
y = [0 2754.5 4043.3 5376.3 5050.4];
the linear function of these two vector is define by
F= [1149.73 , 37.63];
therefore the estimation is equal to
z= [ones(5,1) x']*F';
which is
z = [1149.73 1519.67 4051.96 5589.35 4912.65];
and if it is plotted
plot(x,y,'b.');
hold on;plot(x,y,'b-');
hold on; plot(x,z,'-r');
The linear z ( red line) is showing correctly. Now I want to plot it for all possible combination of x and y using grid and I need to have a mesh for all inputs
[X,Y] = meshgrid(x,y);
but how to make the Z matrix to show the intensity plot of function Z? The Z suppose to have high intensity close to z value and less value far from it. I should suppose to get something like this
Thanks
P.S: the F is calculated using pinv (least square).
You have to interpolate the scattered data to plot it on grid. Here is a simple example for your x, y and z vectors
xi=linspace(min(x),max(x),100)
yi=linspace(min(y),max(y),100)
[XI YI]=meshgrid(xi,yi);
ZI = griddata(x,y,z,XI,YI);
contourf(XI,YI,ZI)
Suppose we have
x=linspace(-1,1,25);
y=linspace(-1,1,25);
[X,Y]=meshgrid(x,y);
Z = X.^2 - Y.^2;
surf(Z)
How does MATLAB calculate the parametric curves (the black lines in the above figure) for obtaining the surface? Are there any explicit formulas to do that? If the parametrization is (u,v) then how to get MATLAB to spit out the
u=f(x,y,z)
v=g(x,y,z)
functions?
The black line on the surface is described by three vectors corresponding to x,y and z coordinates. For example, if you wish to extract the line corresponding to x=x(5)=-0.6667 you need to extract three vectors that are already contained in the meshgrid and Z-array - X(5,:),Y(5,:),Z(5,:):
x=linspace(-1,1,25);
y=linspace(-1,1,25);
[X,Y]=meshgrid(x,y);
Z = X.^2 - Y.^2;
hold off
surf(X,Y,Z)
hold on;
plot3(X(5,:),Y(5,:),Z(5,:),'r','LineWidth',5)
axis square
Similarly, if you want to extract the line at y=y(5)=-0.6667, then you need: X(:,5),Y(:,5),Z(:,5):
x=linspace(-1,1,25);
y=linspace(-1,1,25);
[X,Y]=meshgrid(x,y);
Z = X.^2 - Y.^2;
hold off
surf(X,Y,Z)
hold on;
plot3(X(:,5),Y(:,5),Z(:,5),'r','LineWidth',5)
axis square
Hope that helps
In matlab, I have a vector, say x and a function of x say y. I want to plot x and y in matlab.
The problem is I want smooth curve (not in a sense of smooth texture but differentiable, and without sharp bends). Matlab, with plot, simply joins the points and the plotted curve has sharp bends.
Is there a way I can resolve this?
Following Dan and wakjah, what you need is to interpolate x and y to more sample points
plot( x, y, '+r' ); % plot the original points
n = numel(x); % number of original points
xi = interp1( 1:n, x, linspace(1, n, 10*n) ); % new sample points
yi = interp1( x, y, xi );
hold all;
plot( xi, yi ); % should be smooth between the original points
I'm trying to plot a 3D surface in Matlab and I want to "compress" the plot a little bit in the z dimension. Now the lengths of x, y and z axes are the same, and the plot looks like a cube. I'd like it to look flatter in the z dimension, without altering the axes limits.
Is there any easy way to achieve this?
Try fiddling with the DataAspectRatio and the PlotBoxAspectRatio properties of the axes, which may also be controlled by the pbaspect and daspect commands, correspondingly.
Example
%// Plot surface
[X, Y] = meshgrid(-10:.1:10, -10:.1:10);
Z = 100 - X .^ 2 - Y .^ 2;
surf(X, Y, Z, 'EdgeColor', 'None')
%// Flatten the z-axis a bit
pbaspect([1 1 .2])
daspect([1 1 50])
Original plot:
Flattened plot: