0

I have been trying to create 3D XYZ Line Plot in Matplotlib and I have no idea how to create the negative axes and multiple lines starting from the origin.

I have looked through all the galleries and although there seem categories from line plots, most of them are 2-D or none showing multiple lines in the positive AND negative axis. I have done the math and here is the graph.

3D Line Plot with Multiple Axes

Here are the particular values for this one in the format(vector:[x,y]): x1: [1,1], x1':[1,-1], y1: [2,-1], y1': [-1,-2], z1: [-2,-3], z1':[-3,2]

This is my template code so far that I got off of an online website and I have been playing around with it.

fig, ax = plt.subplots(subplot_kw={'projection': '3d'})

datasets = [{"x":[1,0,0], "y":[0,1,0], "z":[0,0,-1], "colour": "red"} for _ in range(6)]

for dataset in datasets:
    ax.plot(dataset["x"], dataset["y"], dataset["z"], color=dataset["colour"])

plt.show()

For the results I am looking for I end up getting just a singular line and have no idea how to create multiple ones splitting into several directions.

1

1 Answer 1

1

It seems like you are trying to draw several vectors from the origin to a specific xyz point. I would rewrite the format of your dataset to have a series of [x,y,z] coordinates for the end of each vector, then do:

datasets = {"x1": [1,2,-2], "x2":[1,-2,2], "x3":[3,-2,-2]}

fig, ax = plt.subplots(subplot_kw={'projection': '3d'})
for key,p in datasets.items():
    ax.plot([0,p[0]], [0,p[1]], [0,p[2]], label=key)

ax.legend()

plt.show()

enter image description here

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.