Colorplot in Julia with awkward data format

Viewed 56

I have data in the form of a list of tuples (x,y,z) with no particular ordering on the (x,y) values. I want to make a color plot in the x-y plane where z is represented by a color, using the PyPlot function

pcolor

The issue is this function accepts data in the format arr_x,arr_y,image where arr_x and arr_y are 1D arrays and image is a 2d Array such that image[i,j] corresponds here to the z value for x=arr_x[i],y=arr_y[j].

Is there a simple way to do this (without constructing the 2D array image, which would be annoying).

1 Answers

Are you looking for scatter?

using Plots, Unzip # Unzip to go from list of tuples to tuple of lists
data = [(randn(), randn(), randn()) for _ in 1:200] # list of (x,y,z) tuples
x, y, z = unzip(data) # get vectors out of the tuple
scatter(x, y, zcolor=z)

will output enter image description here

Related