MATLAB Color Points According to Variable

In summary, the conversation discusses the task of creating a 2D scatter plot with three variables - Kurth Phase, invariant latitude, and changes in magnetic field readings. The goal is to represent a spacecraft's orbit around a planet by coloring the points on the plot according to the changes in magnetic field. The steps to achieve this are mentioned, including using the scatter function with a color vector and the colorbar command. The conversation ends with the realization that the scatter function can automatically create equal transitions for the color spectrum.
  • #1
darkfall13
33
0
I have been tasked with making a plot with a couple variables of available data. I'm to make a normal 2D scatter plot of the data with respect to 2 of the variables given, easy enough. But then I'm supposed to color (from red to blue) each point according to a 3rd variable, which is a derivative of a couple other variables (getting convoluted yet?). When I asked what this is about I was told its supposed to be a spacecraft orbit around a planet, where x-axis is Kurth Phase (a moving Saturn SKR coordinate), y-axis invariant latitude. And the derivative spoken of earlier is supposed to be changes in the magnetic field readings taken with respect to latitude). So that with the end result you will have a line (of points where the data was taken) representing the spacecraft trajectory but colored to indicate how the magnetic field is changing to signify places where there is strong changes or weak changes.

When explained it makes sense to me, but I can't see how I'm supposed to code this. What steps do I take to color individual points according to some color scheme/variable?
 
Physics news on Phys.org
  • #2
I've been thinking a bit on this and I can see I'll need some sort of variable to define the stepping through different color shades, and to define how many shades I'll be wanting. I see the regular "colorbar" command seems to be the right color scheme. But how do I apply to the individual elements of the plot?
 
  • #3
Try plotting the points using scatter()...
 
  • #4
Wow as much as I thought that didn't help I didn't realize the scatter function can take a vector for color values, and it automatically creates equal transitions for the spectrum. Thank you so much!
 
  • #5


To color individual points according to a variable in MATLAB, you can use the "scatter" function with the "c" argument. This allows you to specify a vector of values that correspond to the color of each point in your scatter plot. For example, if your third variable is called "magnetic field changes" and you have a vector of values for this variable called "changes", you can use the following code to create a scatter plot with points colored based on the changes in the magnetic field:

scatter(x,y,[],changes,'filled')

This will create a scatter plot with x and y as the coordinates, an empty vector for the size of the points, and the "changes" vector for the color. You can also specify a color map to have a range of colors from red to blue, such as:

colormap('cool')

This will create a color map ranging from blue to red, with blue representing the lowest values and red representing the highest values. You can also customize the color map to your liking using the "colormap" function.

In summary, to color individual points according to a variable in MATLAB, you will need to use the "scatter" function with the "c" argument and specify a vector of values for the color, along with a color map if desired.
 

1. How can I change the color of points in a MATLAB plot according to a specific variable?

To change the color of points in a MATLAB plot according to a specific variable, you can use the 'Color' property and specify a variable as the value. For example, if your variable is called 'category' and has three possible values (1, 2, and 3), you can use 'Color = category' to assign a different color to each category.

2. Can I use a custom color map to assign colors to points based on a variable?

Yes, you can use a custom color map to assign colors to points based on a variable in MATLAB. You can create a custom color map using the 'colormap' function and then use it with the 'Color' property to assign colors to points based on a variable.

3. How do I create a color legend for a MATLAB plot with color-coded points?

To create a color legend for a MATLAB plot with color-coded points, you can use the 'legend' function and specify the colors and labels for each category. You can also use the 'Color' property to assign the same colors to the points and the legend.

4. Is it possible to change the shape of the points in a MATLAB plot according to a variable?

Yes, it is possible to change the shape of points in a MATLAB plot according to a variable. You can use the 'Marker' property and specify a variable as the value. For example, if your variable has three possible values (1, 2, and 3), you can use 'Marker = category' to assign a different shape to each category of points.

5. Can I create a scatter plot with different colors and shapes for each point based on multiple variables?

Yes, you can create a scatter plot with different colors and shapes for each point based on multiple variables in MATLAB. You can use the 'Color' and 'Marker' properties together to assign colors and shapes to points based on multiple variables. You can also use the 'legend' function to create a legend for the different combinations of colors and shapes.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Calculus and Beyond Homework Help
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
3K
Back
Top