Scatter Plot Extension to Entire Figure

I have vectors of x and y data, as well as data that parameterizes the color of the scatter dots in another vector. I am graphing them with:
"scatter(x, y, dotSize, colorParameter, 'filled')"
This plots the colored dots in their correct positions. What I want to do is create a blanket graph that simply shows the color gradient. I do not want individual points, simply areas based on the points. How do I go about this?
Thanks in advance.

 Accepted Answer

My guess is that you want a surface plot. Getting from points to a surface can be relatively straightforward if your data are gridded (regularly-spaced in the x and y coordinates), however you will need to interpolate them to a grid if they are not originally gridded. That requires that you first create regularly-spaced vectors for your x and y data, then use meshgrid to create the necessary matrices, and griddata (the most straightforward to use) to interpolate the z-data to a grid that surf or mesh can plot.

6 Comments

Thanks, but I'm actually looking for something far simpler. My data points are irregular floating point values (not going to be easy to make regular), and meshgrid will take forever (there are hundreds of thousands of points). I'm just looking to fill in the space between the points.
My pleasure.
The vectors that meshgrid uses do not have to account for every point. For example, if you only want a (50x50) grid, the linspace and meshgrid calls would be:
xv = linspace(min(x), max(x), 50);
yv = linspace(min(y), max(y), 50);
[X,Y] = meshgrid(xv,yv);
and of course you can have whatever resolution you want on each axis. The griddata call may take a few extra seconds with a large z array, however once you have the matrix it creates, and are happy with it, save it to a .mat file and then load it as needed later. It is not necessary to re-calculate it each time if none of the underlying data change.
I can see how that would work in general, and I really wish I could show you the image that I am getting (research problem, so I can't). I am going to need every point accounted for as the data is far from constant. I have a purple blotch here and as green one there in varying shades. Additionally, as this is for research, I need to rerun it with new data all the time, but I don't mind the delay as long as it works. Could I get this to work with a 512X512 (eventually 8192X8192) grid with eventually millions of points that are not going in one direction, and if so how?
Pretend that vector x contains the x values (floats from 0 - 512) and y contains that y values. Then vector c contains the colors from -30 to 30. How would you do this?
It is essentially impossible to answer a hypothetical problem with any precision.
I would do as I already described, creating the grid matrices whatever size you want, then doing the interpolation.
Try this (with your own data vectors):
x = rand(1, 1000); % Create Data
y = rand(1, 1000)*2; % Create Data
z = rand(1, 1000)*60-30; % Create Data
Nx = 250; % Defines ‘X’ Grid Resolution
Ny = 300; % Defines ‘Y’ Grid Resolution
xv = linspace(min(x), max(x), Nx); % Interpolation Grid Vector
yv = linspace(min(y), max(y), Ny); % Interpolation Grid Vector
[X,Y] = meshgrid(xv, yv); % Create Grids
Z = griddata(x,y,z,X,Y); % Interpolate
figure
surf(X, Y, Z)
shading('interp')
grid on
You may have to experiment with the colormap and caxis functions to get the colors you want. Choose ‘Nx’ and ‘Ny’ to give you the resolution you want.
That's perfect. Thank you so much.
For the sake of formatting, is there a more programatically efficient way to graph it if all I care about is the overhead view? And is there a way to make it programatically go to overhead view?
Also, I have created a bogus version of the data if it helps. There are more points and the colring is supposed to be more chunked, but it covers the idea.
test.png
My pleasure.
To create an overhead view of the surf plot, add:
view(0,90)
after it:
figure
surf(X, Y, Z)
shading('interp')
grid on
xlabel('X')
ylabel('Y')
view(0,90)
The x-axis is along the lower edge of the figure, and the y-axis is along the left edge.

Sign in to comment.

More Answers (0)

Products

Release

R2019a

Community Treasure Hunt

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

Start Hunting!