Black Lives Matter. Please consider donating to Black Girls Code today.

Matplotlib figure cannot be transforemed into plotly

Hey all,

I am trying to to convert a [treemap](http://scipy built on matplotlib to plotly, but I am getting an error:

“Empty data list found. Make sure that you populated the list of data objects you’re sending and try again.
Questions? Visit

I would like to use the treemap in #dash, that’s why I need to transform it.

Here is the code:

#Uses algorithm straight from

#James Casbon 29/7/2006

import functools
import pylab
from matplotlib.patches import Rectangle
from plotly.offline import iplot_mpl

class Treemap:
    def __init__(self, tree, iter_method, size_method, color_method):
        """create a tree map from tree, using itermethod(node) to walk tree,
        size_method(node) to get object size and color_method(node) to get its 

        self.fig, = pylab.subplots()
        pylab.subplots_adjust(left=0, right=1, top=1, bottom=0)[])[])

        self.size_method = size_method
        self.iter_method = iter_method
        self.color_method = color_method

    def addnode(self, node, lower=[0,0], upper=[1,1], axis=0):
        axis = axis % 2
        self.draw_rectangle(lower, upper, node)
        width = upper[axis] - lower[axis]
            for child in self.iter_method(node):
                upper[axis] = lower[axis] + (width * float(self.size_method(child))) / self.size_method(node)
                self.addnode(child, list(lower), list(upper), axis + 1)
                lower[axis] = upper[axis]

        except TypeError:

    def draw_rectangle(self, lower, upper, node):
        r = Rectangle( lower, upper[0]-lower[0], upper[1] - lower[1],
                   facecolor= self.color_method(node))

size_cache = {}
def size(thing):
    if isinstance(thing, int):
        return thing
    if thing in size_cache:
        return size_cache[thing]
        size_cache[thing] = functools.reduce(int.__add__, [size(x) for x in thing])
        return size_cache[thing]
import random
def random_color(thing):
    return (random.random(),random.random(),random.random())

tree= ((5,(3,5)), 4, (5,2,(2,3,(3,2,2)),(3,3)), (3,2) )
tree = Treemap(tree, iter, size, random_color)



Would you know where is the problem please?