0
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np


fig = plt.figure()
ax = fig.gca(projection='3d')

# Make data.
X = np.arange(-5, 5, 0.25)
Y = np.arange(-5, 5, 0.25)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)

ax.plot_trisurf(X, Y, Z, cmap='viridis', edgecolor='none')

plt.show()

I tried to plot this data in form of triangular data but I get this error:

ValueError: x and y must be equal-length 1-D arrays

Can someone help me on it?

6
  • If you want to plot data on a regular, rectangular grid, use plot_surface. Commented Aug 31, 2019 at 15:26
  • Yes, thank you. but for now, I'm searching for plotting it in a triangular grid Commented Aug 31, 2019 at 16:30
  • Why? The grid is already regular. Commented Aug 31, 2019 at 16:57
  • using the plot_surface I get this figure: matplotlib.org/_images/surface3d_demo1.png. but I want it to look some way like that: jakevdp.github.io/PythonDataScienceHandbook/… Commented Aug 31, 2019 at 17:00
  • The example uses random numbers. In your case it would be X = np.random.rand(1000)*10-5; Y = np.random.rand(1000)*10-5; Z = np.sin(np.sqrt(X**2 + Y**2)) Commented Aug 31, 2019 at 17:18

1 Answer 1

1

In triangular surface plot X,Y,Z must be one dimensional array rather than two dimensional as in case of wireframe and surface plot. Don't use np.meshgrid().

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.