TransWikia.com

How to create a color code for points based on 3rd dimension with ListPlot or ListLogLogPlot

Mathematica Asked by gummypenguin on February 7, 2021

I have seen some similar posts but could not quite find what I am looking for.

I would like to create a 2D plot with discrete points that are color coded by a 3rd dimension value. The color function I am trying for is a rainbow color scheme that changes linearly between the smallest and largest values of the 3rd dimension. This would be similar to what ListPointPlot3D seems to do automatically if you specify a color function, but with a 2D plot. Here is the example of the output of the ListPointPlot3D color coded based on the z dimension:

example 3D with correct color function coloring

From the code

ListPointPlot3D[data, ColorFunction -> "Rainbow",PlotRangePadding -> None, BaseStyle -> {14, Bold}]

The example data can be found here:
https://www.dropbox.com/s/6mvpo1kiw5b1t2o/example_points_color_coding.csv?dl=0

Any thoughts are greatly appreciated!

This example is not for geographic data, but it seems like this kind of function would also be very useful for geographic data, so I am surprised there is no built-in version for points on a 2D plot in Mathematica (although I could have missed it!).

One Answer

lpp3d = ListPointPlot3D[data, ColorFunction -> "Rainbow"]

enter image description here

Rescale the last column of data, then style each pair of first two coordinates with ColorData["Rainbow"] evaluated at the rescaled value of the third column.

data2 = data;
data2[[All, 3]] = Rescale[data2[[All, 3]]];
ListPlot[Style[#[[;; 2]], ColorData["Rainbow"][#[[3]]]] & /@ data2, 
 AspectRatio -> 1, Frame -> True]

enter image description here

Alternatively, if the surface does not bend on itself, post-process the output of ListPointPlot3D to remove the third coordinates of Point primitives:

Graphics[Replace[lpp3d[[1]], Point[x_] :> Point[x[[;; 2]]], {0, Infinity}], 
   AspectRatio -> 1, Frame -> True]

enter image description here

Answered by kglr on February 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP