Reputation: 11
I have been trying to import a text file and plot it in python using "wireframe", although I keep getting an error saying:
"ValueError: shape mismatch: objects cannot be broadcast to a single shape".
I would appreciate it if anyone could help me with this. my input text file format is like:
11 12 13 14
21 22 23 24
31 32 33 34
and the code is:
`import os
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np
data = np.genfromtxt('X1slackresultsforplot.txt', delimiter=' ')
x = [0.78,0.79,0.8]
y = [10,20,30,40]
Z = np.array(data)
X, Y = np.meshgrid(x, y)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_wireframe(X,Y,Z,rstride=10,cstride=10)
plt.show()`
Thanks.
Upvotes: 1
Views: 392
Reputation: 43
X and Y have shape (4, 3), but Z has shape (3, 4). Perhaps you want the transpose of Z? The following runs without an error:
ax.plot_wireframe(X,Y,Z.T,rstride=10,cstride=10)
Upvotes: 1