Plotting data in Mathematica certain colours depending on

In summary, the conversation discusses how to make a scatter plot in Mathematica using a list of data in .csv format. The goal is to plot the points with the third column determining the color. The solution involves importing the data, separating it into true and false values, and then using ListPlot and graphics primitives to change the colors. Potential issues with combining multiple plots are also mentioned.
  • #1
stripes
266
0

Homework Statement



I have a list of data in .csv format that looks like the following:

10 5 TRUE
10.1 5.1 TRUE
10.2 5.2 FALSE
10.3 5.3 FALSE
10.4 5.4 FALSE
10.5 5.5 TRUE
10.6 5.6 TRUE
...
There are thousands of entries.

I want to make a scatter plot in Mathematica where it plots the points {10, 5}, {10.1, 5.1}, etc., but I want the ones with TRUE to be blue, and FALSE to be red.

Homework Equations



--

The Attempt at a Solution



I've tried using a while loop then an if statement to do this, but it seems to be an infinite loop. What I did was:

homeruns = column3 (so this is now a list with TRUE FALSE TRUE FALSE etc.)
angles = column2
initialV = column1

Code:
ListPlot[Transpose[{angles, initialV}], i=0; while [i<length[homeruns], If [ truefalse[[i]], PlotStyle -> {Blue}, PlotStyle -> {Red} ] i++; ]]

But this is just stupid. How could I go about making a plot where certain sections of the plot will be one colorr vs another colour, depending on that point's truth value?
 
Physics news on Phys.org
  • #2
In[1]:= data = Import["data.csv"]

Out[1]= {{10, 5, "TRUE"}, {10.1, 5.1, "TRUE"}, {10.2, 5.5, "FALSE"}, {10.3, 5.6, "FALSE"}, {10.4, 5.7, "FALSE"}, {10.5, 5.5, "TRUE"}, {10.6, 5.6, "TRUE"}}

In[2]:= truedata = Cases[data, {x_, y_, "TRUE"} :> {x, y}]

Out[2]= {{10, 5}, {10.1, 5.1}, {10.5, 5.5}, {10.6, 5.6}}

In[3]:= falsedata = Cases[data, {x_, y_, "FALSE"} :> {x, y}]

Out[3]= {{10.2, 5.5}, {10.3, 5.6}, {10.4, 5.7}}

In[4]:= ListPlot[{truedata, falsedata}, Joined -> True]

Out[4]= ...PlotSnipped...

And then you can begin exploring graphics primitives to change colors of individual plots, points, etc

But watch out for combining several plots when some versions Mathematica will take the PlotRange from the first data set and ignore the range of subsequent data sets. You can overcome that by giving an explicit PlotRange large enough to show all your data
 

1. How can I plot data in Mathematica using specific colors?

In order to plot data in Mathematica using specific colors, you can use the PlotStyle option within the Plot function. This option allows you to specify a list of colors to be used for each data set in your plot. Alternatively, you can also use the ColorFunction option to map a color scheme to your data based on a specified function.

2. Can I assign different colors to different data points in a plot?

Yes, you can assign different colors to different data points in a plot by using the PlotMarkers option within the Plot function. This option allows you to specify a list of markers to be used for each data point in your plot, and each marker can have its own color.

3. How do I change the default colors used in a plot?

To change the default colors used in a plot, you can use the DefaultColor option within the Plot function. This option allows you to specify a single color that will be used for all data sets in your plot.

4. Can I create a custom color scheme for my plot?

Yes, you can create a custom color scheme for your plot by using the ColorData function. This function allows you to specify a range of colors and create a custom color function that can be used in your plot by using the ColorFunction option within the Plot function.

5. How can I create a legend for my plot with different colored data sets?

To create a legend for a plot with different colored data sets, you can use the PlotLegends option within the Plot function. This option allows you to specify a list of labels for each data set in your plot, and the legend will automatically display the corresponding colors for each label.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
8
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • Advanced Physics Homework Help
Replies
1
Views
5K
  • Differential Equations
Replies
4
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
Back
Top