Plots makes notebooks too large in IJulia

#1

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?

0 Likes

#2

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 https://github.com/fredrikekre/Literate.jl, and just call the plot commands from there (like https://github.com/fredrikekre/Literate.jl/blob/22c6d530d3d331cd0b260c745bd1d48274c56dfd/examples/example.jl#L66-L70). 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.

3 Likes

#3

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.)

2 Likes

#4

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

0 Likes

#5

Why not

using Plots
default(fmt = :png)
0 Likes

#6

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.

Related?

0 Likes

#7

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

#8

nbstripout maybe? (If storage is the concern)

0 Likes

#9

Here is a strange observation:

The following cell immediately increases the notebook size to 16MB

using Plots
gr(size=(600,400))
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.

0 Likes

#10

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.

0 Likes

#11

This is what inserts the javascript:

Opened a Plots issue: https://github.com/JuliaPlots/Plots.jl/issues/1724

1 Like

#12

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

0 Likes

#13

Doesn’t look like it.

0 Likes

#14

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.

edit
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.

0 Likes

#15

What is inside the notebook (as in you open it with a text editor and look)? I remember https://github.com/JuliaPlots/Plots.jl/issues/1724 but that should be fixed by now I think.

1 Like

#16

@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.

0 Likes

#17

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