0

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.

Hagbard
  • 3,430
  • 5
  • 28
  • 64
  • I do not understand what you try to achieve (what are input and expected output?) but [this](https://stackoverflow.com/q/44001613/8881141) seems to be of interest. And are you aware of [quiver](https://matplotlib.org/3.3.1/api/_as_gen/matplotlib.pyplot.quiver.html)? There is also [this](https://stackoverflow.com/a/34018322/8881141). – Mr. T Jan 12 '21 at 18:18
  • The expected output is seen in the first image. I'm aware of quiver but I'm not so sure anymore whether matplotlib is really to right tool for my task. – Hagbard Jan 13 '21 at 15:00
  • At least to me, the connection between code and the expected output is not clear. I also do not understand what your specific obstacle is to implement the plotting of 3D lines. I link to [this](https://stackoverflow.com/a/49711687/8881141), [this](https://stackoverflow.com/a/64601416/8881141), and [this](https://stackoverflow.com/a/65181776/8881141) as animated examples of plotted 3D lines that you may or may not want to translate into static images. Good luck with your project. – Mr. T Jan 13 '21 at 15:33
  • 1
    Accidentally [seen this](https://stackoverflow.com/a/55171754/8881141). But now I am really out of here. – Mr. T Jan 13 '21 at 19:23

1 Answers1

1

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()
Marcus Cazzola
  • 313
  • 1
  • 9
  • Thank you for the tip. Plotly seems to be a nice alternative. Unfortunately, you did not directly answer my question or provide a detailed way to solve the issue with Plotly. – Hagbard Jan 12 '21 at 12:49
  • I edited my answer. The code makes you plot multiple lines in plotly. – Marcus Cazzola Jan 12 '21 at 19:03
  • Thank you. That's a better starting but still not what I'm really looking for. – Hagbard Jan 13 '21 at 14:58