Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
349 views
in Technique[技术] by (71.8m points)

python - Plotting multiple colored lines and vectors in 3D with matplotlib

I'm struggling to create a 3-D plot with multiple colored lines and vectors in matplotlib. The end result should look as follows:

Desired output

I already found this question. The code

from mpl_toolkits.mplot3d.axes3d import Axes3D
import matplotlib.pyplot as plt
fig, ax = plt.subplots(subplot_kw={'projection': '3d'})

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

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

plt.show()

results in the following output:

Intermediate output

That's a good starting point but unfortunately not quite what I'm looking for as I don't want to have a grid in the background and clearly distinguishable coordinate axes. Furthermore, the xticks and yticks should not be visible.

Any help is highly appreciated.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I made multiple lines in Plotly. image of plot

import plotly.express as px
import pandas as pd
#Line 1
d = {"x":[1,2], "y":[1,4], "z":[0,0], "line":[0 for i in range(2)]} #line = [0,0]. index for multible lines
df = pd.DataFrame(data=d)
#Line 2
d2 = {"x":[4,2], "y":[5,4], "z":[3,2], "line":[1 for i in range(2)]} #line = [1,1]. index for multible lines
df2 = pd.DataFrame(data=d2)

#One data frame
df = df.append(df2)

fig = px.line_3d(df, x="x", y="y",  z="z", color="line")
fig.show()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...