I'd like to do something similar to pyplot.scatter
using the Datashader module in python, specifying an individual (x,y), RGB\hex value for each point independently:
#what i'd like to do, but using Datashader:
import numpy as np
#make sample arrays
n = int(1e+8)
point_array = np.random.normal(0, 1, [n, 2])
color_array = np.random.randint(0, 256, [n, 3])/255 # RGB. I can
#convert between it and hex if needed
#the part I need - make an image similar to plt.scatter, using datashader instead:
import matplotlib.pyplot as plt
fig = plt.figure()
plot = fig.add_subplot(111)
fig.canvas.draw()
plot.scatter(point_array[:, 0], point_array[:, 1], c=color_array)
img = np.fromstring(fig.canvas.tostring_rgb(), dtype=np.uint8, sep='')
img = img.reshape(fig.canvas.get_width_height()[::-1] + (3,))
So that img
is an RGB numpy array (or a PIL array, or anything which can be saved as an image through python)
Things I've Tried
I have looked at datashader.Canvas.points
and how it handles 3 dimensional pandas arrays, and I think I can use it with a color_key
of only red, only green, and only blue values with the "linear interpolation" it does between labels, but I didn't manage to really make it work (got stuck with the pandas side of things, as I mostly use just numpy for everything).