Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python warning: plotly.graph_objs.Line is deprecated

Although everything works fine, I would like to know whether there is a way to fix what is provoking this warning:

plotly.graph_objs.Line is deprecated. Please replace it with one of the following more specific types

  • plotly.graph_objs.scatter.Line
  • plotly.graph_objs.layout.shape.Line
  • etc.
like image 765
Nip Avatar asked May 19 '26 19:05

Nip


2 Answers

For me, replacing go.Line with go.Scatter and appending mode='lines' did the trick. Didn't have to change anything else, and the warning is gone.

Example:

fig.add_trace(
  go.Scatter(
    x=x, 
    y=y_upper_limit, 
    name='Upper Bound', 
    marker=dict(
      color="Red"
    ),
    mode='lines',
    fill='tonexty',
    fillcolor='rgba(167, 167, 167, 0.12)',
  )
)
like image 187
Vinícius Queiroz Avatar answered May 21 '26 10:05

Vinícius Queiroz


Fixing the warning regarding deprecated functions may variate, depending on the packages at use. In my particular case, I was using the "Line" function from "plotly" package. This function was being called from another package. In the latter package there was a .py file (I used "IDLE (Python 3.8 64-bit)" to edit it) that had the following code line:

from plotly.graph_objs import Line

Then, I first tried replacing that line with the suggestions provided by the warning. After a couple of tries, I ended up using the code line:

from plotly.graph_objs.scatter.marker import Line

My final script works fine like in the beginning, but this time with no warnings at all.

Note: In my case, the packages were installed in "C:\Users\NIP\AppData\Roaming\Python\Python38\site-packages"

I hope this helps.

like image 20
Nip Avatar answered May 21 '26 09:05

Nip



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!