0

I'm currently trying to plot multiple 2d line plots evenly distributed in a 3d space using plotly.express line_3d. The plot comes out withsome weird lines crossing each slice of data.

enter image description here

enter image description here

I'm using data from a df like this one:

import pandas as pd

df = pd.DataFrame({'Data_Apontamento': {300: Timestamp('2021-01-02 00:00:00'),301: Timestamp('2021-01-02 00:00:00'),302: Timestamp('2021-01-02 00:00:00'),303: Timestamp('2021-01-02 00:00:00'),304: Timestamp('2021-01-03 00:00:00'),306: Timestamp('2021-01-03 00:00:00'),307: Timestamp('2021-01-03 00:00:00')},
 'Descricao_Produto': {300: 14,301: 6,302: 11,303: 13,304: 4,306: 2,307: 3},
 'Qtde_Apontada': {300: 0.0,301: 0.0,302: 0.0,303: 0.0,304: 0.0,306: 0.0,307: 1.75},
 'rolling_mean': {300: 0.0,301: 0.0,302: 0.0,303: 0.0,304: 0.3333333333333333,306: 0.0,307: 3.8214285714285716}})

And I've written the code as such,

import plotly.express as px

fig = px.line_3d(df, x = 'Data_Apontamento', y = 'Descricao_Produto', z = 'rolling_mean', color = 'Descricao_Produto')
fig.write_html(r'graphs\rolling_expre.html')

I can't find any reason for the appearance of those straight lines.

  • 2
    Please don't share your data as an image, but rather as a part of your code snippet like [this](https://stackoverflow.com/questions/63163251/pandas-how-to-easily-share-a-sample-dataframe-using-df-to-dict/63163254#63163254) – vestland Jun 14 '21 at 17:29
  • Hello Vestland! Okk Thanks for the heads up! Should I edit the question with the whole data or just a small part of it? – Lucas Corbanez Jun 14 '21 at 17:37
  • A sample of your data is enough as long as you're able to reproduce your issue. The linked resource shows how to do that with `df.tail()` – vestland Jun 14 '21 at 17:54
  • Those two snippets only produces an empty plot on my end. Please try to restart your kernel and run it on your end to confrm. – vestland Jun 14 '21 at 18:28
  • 1
    I see. I can not reproduce the error with a subset of my data, only with the whole thing... – Lucas Corbanez Jun 14 '21 at 19:00

1 Answers1

0

I figured it out! Plotly draws the line as the points show up. You have the order the dates of the DataFrame before plotting.