# Mathematica - Colour each 2D point by a third coordinate for each point?

• Ruf30
In summary, the conversation discusses the process of plotting 2D data using ListPlot and the challenge of plotting 3D data in the same way, with the third coordinate representing color. The conversation also mentions the use of Mathematica and IDL for creating astronomical plots and the desire to use colors to represent negative and positive redshift values. The expert suggests using the Hue function in Mathematica to achieve this.

#### Ruf30

I'm looking, as an observer, at imaging accretion discs and tori around Kerr black holes. The image of the disc/torus is projected onto a 2D grid (a CCD if you like) so all lensing effects etc. are implicit. Basically, I can plot the image after determining the (x,y) coordinates in the 2D grid. Plotting 2D data using ListPlot and using the Import command for my .dat files (which are a list of (x,y) points) is no problem.

My question is this: How would one plot a list of (x,y,z) data in ListPlot, where each pixel/point is plotted as (x,y) and the third coordinate z (which can represent redshift, radial coordinate etc) is used to colour each pixel, i.e. its corresponding (x,y) coordinates?

Thank you

I don't mind if anybody could tell me how to do this in IDL instead of Mathemtica say? I can use IDL on my university computers also. Anybody, please?

Using Mathematica, suppose your list is in the form L = {{x1,y1,z1},{x2,y2,z2},...,{xN,yN,zN}}, then you could generate a colored graphic using this snippet of code:

Graphics[{Hue[#3], Point[{#1, #2}]} & @@@ L, Frame -> True]

I am not sure how you want to turn your z coordinates into colors, so play around with the Hue function.

Also, although I love Mathematica and recommend it all the time, IDL is the best tool for producing astronomical plots e.g. some astro quirks like smaller magnitudes being brighter stars cause trouble when you try to make Mathematicaplot the y-axis with positive values below the x-axis and negative values above the x axis.

Last edited:
Thanks ExactlySolved, I think I've got it. Well, re: the redshift, I know hue varies between 0 and 1 and I'm playing with it right now. I want my negative redshifts to be coloured shades of green to blue and my positive redshifts shades of yellow-orange-red for increasing z. I've been playing with this for a few hours but have not, as of yet, figured out how to do this.

However, I now have nice colours, which is a start! Thank you again.

## 1. What is Mathematica?

Mathematica is a software program used for mathematical and scientific computing. It is commonly used by scientists, engineers, and researchers to analyze data, perform calculations, and create visualizations.

## 2. How can I use Mathematica to color 2D points based on a third coordinate?

To color 2D points in Mathematica, you can use the ListPlot function and specify a ColorFunction that takes into account the third coordinate. For example, you can use ColorFunction -> Function[{x, y, z}, ColorData["Rainbow"][z]] to color points based on their z-coordinate.

## 3. Can I customize the color scheme for my 2D points?

Yes, you can customize the color scheme by choosing a different ColorData function or by creating your own custom color function using Blend or RGBColor. You can also adjust the range of colors used by specifying the ColorFunctionScaling option.

## 4. Is it possible to add a legend for the colors used in my 2D point plot?

Yes, you can add a legend by using the PlotLegends option in ListPlot. You can also customize the legend by specifying the labels and colors for each category.

## 5. Can Mathematica handle large datasets for coloring 2D points?

Yes, Mathematica has efficient algorithms for handling large datasets. You can also use parallel computing techniques to speed up the process of coloring 2D points for large datasets.