JuliaPlots / Plots.jl

Powerful convenience for Julia visualizations and data analysis
https://docs.juliaplots.org
Other
1.84k stars 355 forks source link

one-line SVG for Jupyter notebooks? #1870

Open clarkevans opened 5 years ago

clarkevans commented 5 years ago

Hello. I'm curious if the output of Plots.jl could be single-line SVG when used inside Jupyter? Normally it shouldn't matter, but when one is committing a notebook into a git repository, the multi-line Jupyter files make for huge 50+ line commits on even trivial changes, it'd be better to have a single line even if it replaces the whole image. Further, GR backend, my SVG plots are 2x smaller than PNG, but PNG is preferred since it results in a 1-line diff for use in source code systems. Thanks.

mkborregaard commented 5 years ago

Can you try updating to the most recent versions on julia 1.0?

clarkevans commented 5 years ago

Mike,

Thanks for your response! The multi-line SVG output was generated with a two line test, using Plots; gr(); plot([sin,cos], 0, 3pi)) using Julia 1.0.3 on Ubuntu 18.04.1 LTS the following package versions.

  [28b8d3ca] GR v0.36.0
  [7073ff75] IJulia v1.14.1
  [91a5bcdd] Plots v0.22.0

The multi-line SVG image ipynb file generated looks like

{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n",
       "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"600\" height=\"400\" viewBox=\"0 0 2400 1600\">\n",
 ...
       "</svg>\n"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "using Plots; gr(); plot([sin,cos], 0, 3pi)"
   ]
  }
 ],
...
}

It's OK to close this ticket, I could use PNG. It just seems that SVG is smaller and prettier, if only it didn't produce such huge diffs when saving .ipynb files, which we use for tutorials/documentation.