I'm rather new to datashader and am doing this as an introductory project and I've hit a snag. I'm trying to plot the numbers from 1 to 10,000 in a spiral like the 3b1b video here, but I want the prime numbers to be in yellow and the others to be in blue, in order for a better overall visualization. I did this by trying to superimpose the primes in yellow on top of a previously generated image of all the numbers in a spiral in blue. However, when I do this I get the error: Unable to allocate 1.49 TiB for an array with shape (800, 800, 800, 800) and data type uint32
. My code is roughly as follows (I've left the unrelated parts out but I may have missed an import or list):
import sympy
import pandas as pd
from math import sin, cos
import datashader as ds
import datashader.composite as ops
from datashader.utils import export_image
#Generate a list of primes
primes = [i for i in range(10000) if sympy.isprime(i)]
#generate polar x and y coords
allx = [cos(num) * num * 1/10000 for num in range(10000)]
ally = [sin(num) * num * 1/10000 for num in range(10000)]
xp = [cos(num) * num * 1/10000 for num in range(10000)]
yp = [sin(num) * num * 1/10000 for num in range(10000)]
#Store the lists into distinct dataframes
primedf = pd.DataFrame({'Xp': xp, "Yp": yp})
df = pd.DataFrame({'Allx':allx, 'Ally':ally})
#create canvas to plot things on
cvs = ds.Canvas(plot_width=800, plot_height=800)
#create aggregate points, these are what are used to generate the image
agg = cvs.points(df, "Allx", "Ally")
#generate the first image
img = ds.tf.shade(agg)
#Do the same things for the prime sets
aggprime = cvs.points(primedf, "Xp", "Yp")
imgprime = ds.tf.shade(aggprime, cmap="yellow")
#Now superimpose imgprime onto img, this is causing the error
img * imgprime
I've tried a few other methods, including exporting it to a png and reading with iio/cv2, gnuplot, and I did something that I forgot with datashader.composite.source.ops, and none of them seem to work which leads me to believe I am on a completely wrong approach. If anyone would have any advice on how to do this I would be super grateful.
Not sure if anyone cares but I found an answer, if you export the datashades as images and reload them with cv2, you can add the array and it will superimpose them.To export:
And then to reload and superimpose:
and the output:
Isn't it cute!