How to plot a 3D data whose axis are not the same shape?
Solution 1:
You need to reshape your data to expand x
and y
to match z
.
Using pure python:
from itertools import product
a,b,c = zip(*(e for x,y,z in zip(*data) for e in product([x],[y],z)))
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(projection='3d')
ax.scatter3D(a, b, c, c=c, cmap='Greens');
Using numpy:
import numpy as np
x, y = np.repeat(np.array(data[:2]), 3, axis=1)
z = data[2]
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(projection='3d')
ax.scatter3D(x, y, z, c=z, cmap='Greens')
output: