1

I want to create a 3D plot like this: it's from an equations. but I don't have any idea again for making this, I've tried sereval times, but the result just a dot, as you can see on the result image. Sorry for my bad english. Here is the expectation result:

enter image description here

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d
from matplotlib import style

plt.figure('SPLTV',figsize=(10,5))
custom=plt.subplot(121,projection='3d')
#x-2y+z=6
x1=np.array([1,-2,1])
y1=np.array([5,3,7])
z1=np.array([6])
custom.scatter(x1,y1,z1)
custom.set_xlabel('X')
custom.set_ylabel('Y')
custom.set_zlabel('Z')
plt.show()

Here's my result :

enter image description here

1 Answer 1

3

What you need is Poly3DCollection. Consider the following modification of your code:

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d
from mpl_toolkits.mplot3d.art3d import Poly3DCollection  # appropriate import to draw 3d polygons
from matplotlib import style

plt.figure('SPLTV',figsize=(10,5))
custom=plt.subplot(121,projection='3d')
#x-2y+z=6
x1=np.array([1, -2, 1])
y1=np.array([5, 3, 7])
z1=np.array([0, 0, 6])  # z1 should have 3 coordinates, right?
custom.scatter(x1,y1,z1)

# 1. create vertices from points
verts = [list(zip(x1, y1, z1))]
# 2. create 3d polygons and specify parameters
srf = Poly3DCollection(verts, alpha=.25, facecolor='#800000')
# 3. add polygon to the figure (current axes)
plt.gca().add_collection3d(srf)

custom.set_xlabel('X')
custom.set_ylabel('Y')
custom.set_zlabel('Z')
plt.show()
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much!! I'll try using poly3dcollection

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.