MPLD3 with Python error

前端 未结 1 1629
别那么骄傲
别那么骄傲 2020-12-21 09:18

I tried to replicate the example found on this website: http://mpld3.github.io/examples/scatter_tooltip.html

But I get the following error: Object of type \'nd

相关标签:
1条回答
  • 2020-12-21 09:36

    There is an open issue raised against this error, the link is https://github.com/mpld3/mpld3/pull/435

    One work-around is to edit the mpld3/_display.py file inside your mpld3 module, the edit will be on below default function

    before:

    def default(self, obj):
        if isinstance(obj, (numpy.int_, numpy.intc, numpy.intp, numpy.int8,
            numpy.int16, numpy.int32, numpy.int64, numpy.uint8,
            numpy.uint16,numpy.uint32, numpy.uint64)):
            return int(obj)
        elif isinstance(obj, (numpy.float_, numpy.float16, numpy.float32, 
            numpy.float64)):
            return float(obj)
        return json.JSONEncoder.default(self, obj)
    

    after:

    def default(self, obj):
        if isinstance(obj, (numpy.int_, numpy.intc, numpy.intp, numpy.int8,
            numpy.int16, numpy.int32, numpy.int64, numpy.uint8,
            numpy.uint16,numpy.uint32, numpy.uint64)):
            return int(obj)
        elif isinstance(obj, (numpy.float_, numpy.float16, numpy.float32, 
            numpy.float64)):
            return float(obj)
        elif isinstance(obj, (numpy.ndarray,)): # add this line
            return obj.tolist() # add this line
        return json.JSONEncoder.default(self, obj)
    

    basically you just added

    elif isinstance(obj, (numpy.ndarray,)): # add this line
                return obj.tolist() # add this line
    
    0 讨论(0)
提交回复
热议问题