Inheritance from FigureWidget class leads to AttributeError

Hey guys,

can’t figure out why my code is not working. I try to create an instance variable in the constructor of my class. This works when the class doesn’t inherit from another class as well as when it inherits from a class I defined within the same scope. But when I try to inherit FigureWidget, I get an AttributeError. The code looks as follows:

import plotly.graph_objects as go
class HeatmapLines(go.FigureWidget):
    def __init__(self):
        self.y_heatmap_lines=4

a=HeatmapLines() 

And the error:

AttributeError                            Traceback (most recent call last)
<ipython-input-104-67db37616276> in <module>
----> 1 a=HeatmapLines()

<ipython-input-103-49446a09e448> in __init__(self)
      1 class HeatmapLines(go.FigureWidget):
      2     def __init__(self):
----> 3         self.y_heatmap_lines=4
      4 
      5 

/usr/local/lib/python3.7/site-packages/plotly/basedatatypes.py in __setattr__(self, prop, value)
    722         else:
    723             # Raise error on unknown public properties
--> 724             raise AttributeError(prop)
    725 
    726     def __getitem__(self, prop):

AttributeError: y_heatmap_lines

I posted this a few days ago in stackoverflow, but nobody seems to be able to help me there so I thought I post it here in case it is something specific to plotly.

Best,
Felix

Hi Felix,

I ran into the same problem and I found a simple wordaround. The solution you’re looking for might be coming a bit late but here it is:

  • the only properties that seem to be allowed are private ones (eg: _y_heatmap_lines),
  • you also to construct your FigureWidget object properties (using super().__init__()).

Try this and it should work fine:

import plotly.graph_objects as go
class HeatmapLines(go.FigureWidget):
    def __init__(self):
        super().__init__()
        self._y_heatmap_lines=4

a=HeatmapLines()