'Returns the JSON for the plot with non-data elements stripped.'

def get_data(self, flatten=False):

    d = dict()
    for (key, val) in list(self.items()):
        if isinstance(val, (PlotlyDict, PlotlyList)):
            sub_data = val.get_data(flatten=flatten)
            if flatten:
                for (sub_key, sub_val) in sub_data.items():
                    key_string = '{0}.{1}'.format(key, sub_key)
                    d[key_string] = sub_val
            else:
                d[key] = sub_data
        else:
            if (self._get_attribute_role(key, value=val) == 'data'):
                d[key] = val
            if ((self._name in graph_reference.TRACE_NAMES) and (key == 'name')):
                d[key] = val
    keys = list(d.keys())
    for key in keys:
        if isinstance(d[key], (dict, list)):
            if (len(d[key]) == 0):
                del d[key]
    return d
