Reputation:
I want to create a PDF from a scatter plot. This is the code I'm currently using:
data = np.column_stack((x, y))
nbins = 100
xmin = -0.5; xmax = 0.5; ymin = -5; ymax = 5
k = kde.gaussian_kde(data.T)
xi, yi = np.mgrid[xmin:xmax:nbins*1j, ymin:ymax:nbins*1j]
zi = k(np.vstack([xi.flatten(), yi.flatten()]))
fig, ax = plt.subplots(figsize=(5.5,4))
plt.pcolormesh(xi, yi, zi.reshape(xi.shape), shading='gouraud', cmap='Purples')
plt.contour(xi, yi, zi.reshape(xi.shape), levels = [0.2, 0.5, 0.7, 1, 1.5], linewidths=1, linestyles='dashed', cmap='viridis')
plt.xlabel('$x$')
plt.ylabel('$y$]')
plt.grid(True, linestyle='--')
ax.set_xlim(xmin, xmax)
ax.set_ylim(ymin, ymax)
fig.savefig('test.png', dpi=600)
plt.close(fig)
And this is the plot I'm getting from the code:
I have two questions about this:
Upvotes: 0
Views: 1306