1

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.

1
  • I think you need to transpose your data: data = data.T Commented Jun 24, 2017 at 18:27

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.