0

How can I plot 3D data as a 2D grid plot in Python?

Similar to hist2D where the third dimension is not frequency but my own data. Let me illustrate:

import numpy as np
import matplotlib.pyplot as plt


# Making some points
npoints = 500
x = np.random.uniform(low=0, high=3, size=npoints)
y = np.random.uniform(low=-3, high=3, size=npoints)
z = np.random.uniform(low=0, high=10, size=npoints)

# plot X Y Z as a grid plot
# like plt.hist2d(x, y) but where frequency = z
plt.colorbar()
plt.show()

enter image description here

Similar question but didn't help: Color 2D Grid with values from separate 2D array

dr_rk
  • 4,395
  • 13
  • 48
  • 74
  • `griddata` or `meshgrid` in the duplicate questions interpolate between grids, but my visualisation is on a discrete grid. I tried something like: `fi = griddata(x, y, f, xi, yi, interp='linear')` – dr_rk Feb 09 '18 at 15:41
  • If you want to get help, remember to notify the user who closed the question (using @ notation). The edit however, does not make this question less duplicate than before. There is no attempt in the question that uses any of the answers from the duplicate. Also, in numerics, *every* grid is discrete, so it's unclear what should be different here. – ImportanceOfBeingErnest Feb 10 '18 at 23:33
  • In addition, you need to make the desired output clear. At the moment you have a "grid" which can contain twice or more the same coordinate. Hence you have several `z` values for the same `x,y` combination. It is hence not obvious what value should be shown for that coordinate. – ImportanceOfBeingErnest Feb 10 '18 at 23:44

0 Answers0