Problem with specifying separate colours for each of my SCATTER points.

86 views (last 30 days)
Hello all,
I got two problems that I needed help with in regards to the scatter function provided by MATLAB.
Problem 1:
So, I'm trying to plot points on the vertices of my polygon. I want the colour of these points to be determined by the angle subtended at that vertex of the polygon. I used a colorbar and have the following code for the scatter function:
scatter(app.UIAxes, x_vals, y_vals, size_of_markers, angles_at_vertices, 'filled');
This works fine for all the polygons that have more than 3 vertices - but when it comes two triangles, since there are three angles within them MATLAB detects my variable, angles_at_vertices as an RGB triplet and gives me the following error:
Warning: Error updating Scatter.
Invalid RGB triplet. Specify a three-element vector of values between 0 and 1.
I was wondering whether there is anyway for me to fix this?
Problem 2:
This is not really much of a problem, but more of an annoyance. Essentially, after i use the scatter function to plot my points onto my polygon, the UIAxes that I'm using gets resized and zoomed in to fit my plots exactly onto the axes.
Here is an example:
This is the before and after:
I was wondering whether there is any way of preventing this resize/zoom effect from hapenning?
Thanks in advance!

Accepted Answer

dpb
dpb on 21 Nov 2021
  1. Read the documentation :)
c Marker color
[0 0 1] (default) | RGB triplet | three-column matrix of RGB triplets | vector | 'r' | 'g' | 'b' | ...
Marker color, specified in one of these forms:
  • Vector — Use different colors for each marker and linearly map values in c to the colors in the current colormap. The length of c must equal the length of x and y. To change the colormap for the axes, use the colormap function. If you have three points in the scatter plot and want the colors to be indices into the colormap, specify c as a three-element column vector.
Note the highlighted last sentence.
2. Use hold on after setting the desired axis limits to not have the 'Auto' scaling property active. Or use xlim and ylim and set the desired limits directly.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!