I'm running into an issue trying to create a color map within a scatterplot. Here's the portion of my code:
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import gaussian_kde
f, ax = plt.subplots()
xy = np.vstack([x, y])
xy = xy[~np.isnan(xy)]
z = gaussian_kde(xy)(xy)
idx = z.argsort()
x, y, z = x[idx], y[idx], z[idx]
plt.scatter(x, y, c=z, cmap='Reds', alpha=0.5)
x
and y
are both columns within my panda dataframe and they both do have NaN
values. I tried taking out all the NaN
values by doing ~np.isnan(xy)
to only get actual values since it wasn't allowing me to take infs or NaNs since I believe gaussian_kde()
was throwing that error. Also, both columns don't align with each other in terms of where those NaN
values are and one column has more NaN
values than the other. Both also have the same amount of elements. When I run my code, it just keeps running and I have to stop it. Any ideas what's possibly wrong?