Plots makes notebooks too large in IJulia


My 16KB notebooks end up 16MB if I keep the output of Plots in them. Is there an IJulia friendly way to use Plots that will not increase the notebook size as much?



If it is due to large SVGs you can display them in png format instead with display(MIME"image/png", plot).

You can also store your notebook in text only format using, and just call the plot commands from there (like The notebooks are then “render targets” (so they are not checked into your main branch of the repo). They could be rendered as part of documentation deployment for example.



You want display("image/png", plot). (Would be nice if there were a way to make this the default in Plots.jl, since SVGs can get large and slow to render very easily.)



Meant to write MIME("image/png") but your way is of course shorter.



Why not

using Plots
default(fmt = :png)


This is perhaps related:

The new IJulia 1.11.1 works nicely on Julia 1.0.0 (thanks!), but it seems as if the new notebooks with plots (using Plots) often do not render on GitHub, at least if they include several plots, and some markdown cells.

It also seems as if the notebook contains a lot of javascript code to show the plot.




One can even use Literate twice, to create a Markdown for the docs and a non executed clean notebook in the main repo for users to follow along

1 Like


nbstripout maybe? (If storage is the concern)



Here is a strange observation:

The following cell immediately increases the notebook size to 16MB

using Plots
default(fmt = :png)

and then the size stays flat (even after adding plenty of more cells).

However, if I instead run that same cell twice, then the size decreases to 15Kb or so.



It’s the Plotly Javascript that gets saved into the Notebook:

     "data": {
      "text/html": [
       "    <script type='text/javascript'>\n",
       "        define('plotly', function(require, exports, module) {\n",
       "     UInt8[0x2f, 0x2a, 0x2a, 0x0a, 0x2a, 0x20, 0x70, 0x6c, 0x6f, 0x74, 0x6c... "
       "        });\n",
       "        require(['plotly'], function(Plotly) {\n",
       "            window.Plotly = Plotly;\n",
       "        });\n",
       "    </script>\n"
     "metadata": {},
     "output_type": "display_data"

That UInt8 vector is 16MB.



This is what inserts the javascript:

Opened a Plots issue:

1 Like


Thanks for looking into this. Is there currently any other way (than “run twice”) to get around this?



Doesn’t look like it.



I have the same problem (Jupyter notebooks that are very large and slow, probably due to plots). I have ran display(MIME("image/png")), but the size of the notebook is the same (15MB).
Is there another solution to this?
The notebook is too slow and gets jammed all the time.

I figured out that I can plot a png using plot(x, y, fmt = :png). The notebook still takes a lot of disk space (~8MB), but it responds much faster.



What is inside the notebook (as in you open it with a text editor and look)? I remember but that should be fixed by now I think.

1 Like


@kristoffer.carlsson sorry for my ignorance, but I am a new user. I am not sure what to look for in the notebook file.
In the link you added, I see they are using Plotly but I am not.



I can confirm that the 16MB blowup does not happen with latest version. I tried GR, Plotly and PlotlyJS backends.

P.S. I am not sure if PlotlyJS is completely functional, it does not seem to respond to hovering mouse pointer by showing the closest value as it used to. I also get a missing dependency (ORCA), which I have to manually install before using PlotlyJS.

1 Like