Please consider this code:
import numpy as np; import matplotlib.pyplot as plt;
from mpl_toolkits import mplot3d
x = np.array([0,1,2,3,4,5])
y = np.array([1,2,3])
z = np.array([[ 0, 1, 4, 9, 16, 25],
[ 0, 2, 8, 18, 32, 50],
[ 0, 3, 12, 27, 48, 75]])
plt.figure().add_subplot(111, projection='3d').plot_surface(x, y, z, rstride=1, cstride=1,cmap='viridis')
This will return: shape mismatch: objects cannot be broadcast to a single shape
.
If you google Python 3D plot for help mostly you will find how to plot from functions by generating data with meshgrid
. However my question is. What is the easiest way to plot when you have an array?
The solution to this problem should look something like this:
For instance one point is (x=3,y=2,z=18)