plotly.io.to_json method does not convert large numbers correctly
Hi, I have some some code here, as below (edited to remove extra logs). I'm converting a plotly figure into json, and then loading it with json loads. You would expect that to preserve the original data.
'
However, as you can see, the "y" data (which had previously been an array of large numbers) are wrongly converted into this "bdata" thing instead.
I was able to solve this and get the data in the format I wanted by going from 6.0.1 -> 5.24.1, which was the last stable build I was using. I think this is a pretty fundamental issue, so let me know if there's anything else I can share.
This may not solve your issue, however I had a similar issue in a client application, rendering the json object using the plotly.js library.
It turned out I was using an outdated plotly javascript library, which in versions prior to v2.28 did not know about bdata (base64 encoded). Once I upgraded to the latest version of plotly.js it worked fine.
@marthacryan suggests adding a base64: bool argument to plotly.io.to_json (similar to pretty: bool) that would control whether data is base64'd or not.
For some context on implementation: the BaseFigure class does the conversion to base64 in the to_dict function here: https://github.com/plotly/plotly.py/blob/1ec864bbed58ee2834a879d323ade4b53bfde364/plotly/basedatatypes.py#L3344. So this is the call stack:
-
to_jsoncallsvalidate_coerce_fig_to_dicthere -
validate_coerce_fig_to_dictcallsBaseFigure.to_dicthere.
So, we'd have to add a flag to plotly.io.to_json and validate_coerce_fig_to_dict and BaseFigure.to_dict.