# Plots makes notebooks too large in IJulia

**URL:** <https://discourse.julialang.org/t/plots-makes-notebooks-too-large-in-ijulia/14550>\
**Category:** General Usage\
**Created:** [September 4, 2018, 8:14pm UTC](https://discourse.julialang.org/t/plots-makes-notebooks-too-large-in-ijulia/14550 "2018-09-04T20:14:23Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![denizyuret](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/denizyuret/32/568_2.png) [@denizyuret](https://discourse.julialang.org/u/denizyuret)\
**Post date:** [September 4, 2018, 8:14pm UTC](https://discourse.julialang.org/t/plots-makes-notebooks-too-large-in-ijulia/14550/1 "2018-09-04T20:14:24Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [September 4, 2018, 8:17pm UTC](https://discourse.julialang.org/t/plots-makes-notebooks-too-large-in-ijulia/14550/2 "2018-09-04T20:17:29Z")

</div>

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](https://github.com/fredrikekre/Literate.jl), and just call the plot commands from there (like [Literate.jl/example.jl at 22c6d530d3d331cd0b260c745bd1d48274c56dfd · fredrikekre/Literate.jl · GitHub](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.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [September 5, 2018, 1:51am UTC](https://discourse.julialang.org/t/plots-makes-notebooks-too-large-in-ijulia/14550/3 "2018-09-05T01:51:57Z")

</div>

> [@kristoffer.carlsson](#):
>
> `display(MIME"image/png", plot)`

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

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [September 5, 2018, 2:37am UTC](https://discourse.julialang.org/t/plots-makes-notebooks-too-large-in-ijulia/14550/4 "2018-09-05T02:37:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [September 5, 2018, 4:00am UTC](https://discourse.julialang.org/t/plots-makes-notebooks-too-large-in-ijulia/14550/5 "2018-09-05T04:00:21Z")

</div>

Why not

```julia
using Plots
default(fmt = :png)

```

---

<div class="post-metadata">

**Author:** ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)\
**Post date:** [September 5, 2018, 8:25am UTC](https://discourse.julialang.org/t/plots-makes-notebooks-too-large-in-ijulia/14550/6 "2018-09-05T08:25:10Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)\
**Post date:** [September 5, 2018, 9:44am UTC](https://discourse.julialang.org/t/plots-makes-notebooks-too-large-in-ijulia/14550/7 "2018-09-05T09:44:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cortner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cortner/32/204_2.png) [@cortner](https://discourse.julialang.org/u/cortner)\
**Post date:** [September 5, 2018, 12:00pm UTC](https://discourse.julialang.org/t/plots-makes-notebooks-too-large-in-ijulia/14550/8 "2018-09-05T12:00:11Z")

</div>

nbstripout maybe? (If storage is the concern)

> **[GitHub - kynan/nbstripout: strip output from Jupyter and IPython notebooks](https://github.com/kynan/nbstripout)**
>
> strip output from Jupyter and IPython notebooks. Contribute to kynan/nbstripout development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)\
**Post date:** [September 5, 2018, 1:54pm UTC](https://discourse.julialang.org/t/plots-makes-notebooks-too-large-in-ijulia/14550/9 "2018-09-05T13:54:59Z")

</div>

Here is a strange observation:

The following cell immediately increases the notebook size to 16MB

```julia
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.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [September 5, 2018, 2:32pm UTC](https://discourse.julialang.org/t/plots-makes-notebooks-too-large-in-ijulia/14550/10 "2018-09-05T14:32:49Z")

</div>

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

```julia
     "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.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [September 5, 2018, 2:55pm UTC](https://discourse.julialang.org/t/plots-makes-notebooks-too-large-in-ijulia/14550/11 "2018-09-05T14:55:40Z")

</div>

This is what inserts the javascript:

> <https://github.com/JuliaPlots/Plots.jl/blob/80151ac1a30c498592ac94ee03d5a7af6d2df8de/src/backends/plotly.jl#L82-L96>

Opened a Plots issue: [using Plots unconditionally inserts 16MB of javascript into notebooks · Issue #1724 · JuliaPlots/Plots.jl · GitHub](https://github.com/JuliaPlots/Plots.jl/issues/1724)

---

<div class="post-metadata">

**Author:** ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)\
**Post date:** [September 5, 2018, 3:36pm UTC](https://discourse.julialang.org/t/plots-makes-notebooks-too-large-in-ijulia/14550/12 "2018-09-05T15:36:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [September 5, 2018, 4:30pm UTC](https://discourse.julialang.org/t/plots-makes-notebooks-too-large-in-ijulia/14550/13 "2018-09-05T16:30:10Z")

</div>

Doesn’t look like it.

---

<div class="post-metadata">

**Author:** ![roi.holtzman](https://avatars.discourse-cdn.com/v4/letter/r/f05b48/32.png) [@roi.holtzman](https://discourse.julialang.org/u/roi.holtzman)\
**Post date:** [March 17, 2019, 11:10am UTC](https://discourse.julialang.org/t/plots-makes-notebooks-too-large-in-ijulia/14550/14 "2019-03-17T11:10:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [March 17, 2019, 2:24pm UTC](https://discourse.julialang.org/t/plots-makes-notebooks-too-large-in-ijulia/14550/15 "2019-03-17T14:24:38Z")

</div>

What is inside the notebook (as in you open it with a text editor and look)? I remember [using Plots unconditionally inserts 16MB of javascript into notebooks · Issue #1724 · JuliaPlots/Plots.jl · GitHub](https://github.com/JuliaPlots/Plots.jl/issues/1724) but that should be fixed by now I think.

---

<div class="post-metadata">

**Author:** ![roi.holtzman](https://avatars.discourse-cdn.com/v4/letter/r/f05b48/32.png) [@roi.holtzman](https://discourse.julialang.org/u/roi.holtzman)\
**Post date:** [March 18, 2019, 10:48am UTC](https://discourse.julialang.org/t/plots-makes-notebooks-too-large-in-ijulia/14550/16 "2019-03-18T10:48:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![denizyuret](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/denizyuret/32/568_2.png) [@denizyuret](https://discourse.julialang.org/u/denizyuret)\
**Post date:** [March 18, 2019, 11:06am UTC](https://discourse.julialang.org/t/plots-makes-notebooks-too-large-in-ijulia/14550/17 "2019-03-18T11:06:21Z")

</div>

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.
