Offline plot to div - encode numpy data as binary blob?

Is there any way to use plotly.offline to store (numpy) data in a div or HTML as a binary blob then have plotly js render it properly?

The HTML file has bits that look like…
“z”: [[0.2866461675771665, 0.36531080671829425, -0.2904632669675007, -0.36149370732795966, -0.049367492181059396, -0.08192231566757988, 0.6849181745604624, 1.268579555423972, 0.2944241042103686, -0.2851544876150079, -0.9762164627387184, 0.1527361407626408] …

I’m trying to reduce the size of my HTML files that have several image plots each with 10^5 - 10^6 data points.
I’ve taken to stripping some of the precision so the json (string)-encoded data have fewer digits, but this seems silly.

Hi @bullale,

Not quite, but I actually have an open pull request in the Plotly.js project that would be the first step: See https://github.com/plotly/plotly.js/pull/2911

Plotly.js already supports accepting numerical arrays and JavaScript TypedArrays. And this PR would add a way to encode these as base64 strings.

But, your example here reminds me that this PR doesn’t yet cover the 2-dimensional case. I’ll add a note over there.

-Jon

Thanks for the quick reply. I searched plotly.py before posting but not plotly.js; I’m glad to see it’s in-progress.
Should one of us create an issue in plotly.py to make this visible there as well?

Sure, that would be great if you would create an issue to track this on the plotly.py side.

Another angle I’ve been thinking about is whether it might make sense to compress the plot specification on the Python side (and in-line in the HTML file) and then decompress it in JavaScript before rendering it. This wouldn’t require the base64 encoding change (although it would work just fine with it as well). Python comes with gzip support, but I haven’t looked into what would be the best way to decompress things on the JavaScript side.

It will probably be a couple of months before I have a chance to work on this, but feel free to dig in yourself if you’re interested in the meantime!

-Jon