creating smooth 2d plot with only a scaled colorvector and (x,y) coordinates | (matlab plotting issue)

326 Views Asked by At

I've an issue with visualizing the data in a correct way.

I have an array with 3 colums and N rows.

DATA =

|x1 y1 v1|
|x2 y2 v2|
|x3 y3 v3|
|   .    |
|   .    |
|   .    |
|xn yn vn|

The first 2 columns represent the x-coordinate and y-coordinate of the Nth-point, while each element of the third column is a scalar value v (ranging from -1 to +1) which must represent a color. How can I create a nice 2D-plot with a colorbar, based on this data-array only?

My attempts:

  • Direct use of surf and mesh-plotcommands resulted in an error, since the COLOR-info needs to be in a matrix-form, but in my case it is only a vector (i.e. the third column).

  • Using a scatter plot with n-rows (I used the following commands)

    pointsize = 20;
    scatter(DATA(:,1), DATA(:,2), pointsize, DATA(:,3),'filled');
    

But the result is not good enough, since I want the complete image filled up with the respective colors (and thus get rid off the white discontinuities). Increasing the number of rows, makes it look denser, but at the end the white spaces are still visible.

Any kind of help is much appreciated.

1

There are 1 best solutions below

0
On

It seems that to generate a continuous surface you will have to use either mesh or surf, but both of them only work for grid data points. So what you can do is to firstly interpolate and/or extrapolate your (x,y,v) data points such that they form a grid. griddata might be a good function to try first. Here is just an example I made up:

% first, make up some scattered data points (degenerated from a grid)
x=1:10;
y=1:10;
[x,y]=meshgrid(x,y);
x=x(1:7:end);
y=y(1:7:end);
v=x.*y;
% plot3(x,y,v) % you can plot to see it in scattered form

% then, reconstruct a grid, interpolate v, and surf it
[xq,yq]=meshgrid(1:0.5:10,1:0.5:10); % a new, denser grid
[Xq,Yq,Vq] = griddata(x,y,v,xq,yq); % interpolate
surf(Xq,Yq,Vq) % 3D color plot, you can just rotate it. Some points are NaN tho.