# VegaLite.jl: size/resolution of pdf output

**URL:** https://discourse.julialang.org/t/vegalite-jl-size-resolution-of-pdf-output/33021
**Category:** Visualization
**Created:** [January 6, 2020, 9:34am UTC](https://discourse.julialang.org/t/vegalite-jl-size-resolution-of-pdf-output/33021 "2020-01-06T09:34:56Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![BenjaminBorn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/benjaminborn/32/4910_2.png) [@BenjaminBorn](https://discourse.julialang.org/u/BenjaminBorn)
#### Post date: [January 6, 2020, 9:34am UTC](https://discourse.julialang.org/t/vegalite-jl-size-resolution-of-pdf-output/33021/1 "2020-01-06T09:34:56Z")

</div>

Is there a way to specify with VegaLite (or maybe other packages) the resolution (or file size) of the pdf output? My goal is to use the pdf figures in a LaTeX document and because I have many figures and each is quite large, the resulting pdf becomes too large. The easiest solution for me would be to reduce the resolution already when saving the VegaLite images. Is that possible?

---

<div class="post-metadata">

### Author: ![dmolina](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmolina/32/5246_2.png) [@dmolina](https://discourse.julialang.org/u/dmolina)
#### Post date: [January 6, 2020, 12:05pm UTC](https://discourse.julialang.org/t/vegalite-jl-size-resolution-of-pdf-output/33021/2 "2020-01-06T12:05:55Z")

</div>

Depends on the package. In VegaLite there are the keywords width and height to change the file size of the figure.

```julia
p = dataset("stocks") |>
       @vlplot(
           :line,
           transform=[
               {filter="datum.symbol=='GOOG'"}
           ],
           x="date:t",
           y=:price, width=800,height=800,
       )

save(p, "/tmp/salida.png")

```

Simply changing width and/or height you can change the size of the figure, and later with save it will use that size.

In other plots packages there is other options. For Plots.jl you can see [Plotting for publications. · Issue #897 · JuliaPlots/Plots.jl · GitHub](https://github.com/JuliaPlots/Plots.jl/issues/897).

---

<div class="post-metadata">

### Author: ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)
#### Post date: [January 6, 2020, 12:15pm UTC](https://discourse.julialang.org/t/vegalite-jl-size-resolution-of-pdf-output/33021/3 "2020-01-06T12:15:15Z")

</div>

No, I think, this is not possible in VegaLite.  
width and height only change the size of the result graph in pixel, not so much the file size. If you try to save different size of the same graph you get nearly the same file sizes for a PDF file. Surely, if you save as PNG, which is a raster/pixel format, you will get larger file size.

This is because, the saved PDF is a vector format where not the pixels are saved but how to draw the graph.

So, if you save your VegaLite graphs as PDFs and than import those PDFs into your LaTeX document, you may have an option at this stage to define the resolution of your result document.

I think the VegaLite part of your problem is to save the graph as an eps, which is encapsulated post script. This format is again a vector format but it is size (paper or canvas size) independent, so it scales to what ever size/resolution you like. But for the details with LaTex I can’t tell.

---

<div class="post-metadata">

### Author: ![dmolina](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmolina/32/5246_2.png) [@dmolina](https://discourse.julialang.org/u/dmolina)
#### Post date: [January 6, 2020, 12:49pm UTC](https://discourse.julialang.org/t/vegalite-jl-size-resolution-of-pdf-output/33021/4 "2020-01-06T12:49:57Z")

</div>

You have reason, the width and height keyworks have help me in generating PNG files, I did not see that he was talking about pdf version. @BenjaminBorn, with eps or other vectorial format you can later set the width parameter in includegraph in Latex and the figure should maintain good quality. With other backends like PGFPlots.jl or [https://github.com/KristofferC/PGFPlotsX.jl](https://github.com/KristofferC/PGFPlotsX.jl) you can integrate it easily in Latex (I think, I actually have not used them).

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [January 6, 2020, 1:15pm UTC](https://discourse.julialang.org/t/vegalite-jl-size-resolution-of-pdf-output/33021/5 "2020-01-06T13:15:46Z")

</div>

> [@BenjaminBorn](#):
>
> resolution (or file size) of the pdf output?

Are you sure about this? PDF is a vector format. The resolution is just a hint for mapping/rendering to physical media (screen, paper, etc) and should not affect the rest of the information in the file, or its size in any way (the only exception would be pixel images embedded in a PDF file, for which resolution could matter, but I don’ think this applies in your case).

---

<div class="post-metadata">

### Author: ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)
#### Post date: [January 6, 2020, 5:36pm UTC](https://discourse.julialang.org/t/vegalite-jl-size-resolution-of-pdf-output/33021/6 "2020-01-06T17:36:21Z")

</div>

So if file size (i.e. bytes on disc) is the concern, then exporting it as a PNG might be the solution, as others have pointed out.

I’ve tried to add a DPI option for the PNG export recently (see [here](https://github.com/queryverse/VegaLite.jl/issues/91)), but am stuck on an upstream problem with that right now.

---

<div class="post-metadata">

### Author: ![MA\_Laforge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ma_laforge/32/385_2.png) [@MA\_Laforge](https://discourse.julialang.org/u/MA_Laforge)
#### Post date: [January 8, 2020, 3:49am UTC](https://discourse.julialang.org/t/vegalite-jl-size-resolution-of-pdf-output/33021/7 "2020-01-08T03:49:28Z")

</div>

### InspectDR & LaTeX

If you are only looking for 2D plots, you could try InspectDR:

It supports EPS, PDF, and SVG as vector formats. In my experience, EPS is ideal for use with LaTeX.

Typically, vector formats tend to have file sizes that are smaller than a reasonable quality pixel-based output.

…unless the data making up the plot is large.

### “F1”-acceleration (dataset is large)

In the case where the dataset is large: InspectDR supports “F1”-acceleration, which drops points when datasets are plotted without glyphs (lines only). See info on `:drop_points` & `pointdropmatrix` in the README.md file ([GitHub - ma-laforge/InspectDR.jl: Fast, interactive Julia/GTK+ plots (+Smith charts +Gtk widget +Cairo-only images)](https://github.com/ma-laforge/InspectDR.jl)).

### .PNG Output & DPI option

If you cannot apply “F1”-accerleration (because it would look wrong when glyphs are drawn), you can always save as a .PNG or other pixel-based format (as you could with most other plotting tool).

InspectDR DOES currently support changing the plot resolution. You can look at demo12.jl as a model:

- [InspectDR.jl/sample/demo12.jl at master · ma-laforge/InspectDR.jl · GitHub](https://github.com/ma-laforge/InspectDR.jl/blob/master/sample/demo12.jl)

It makes use of stylesheets defined in stylesheets.jl:

- [InspectDR.jl/src/stylesheets.jl at master · ma-laforge/InspectDR.jl · GitHub](https://github.com/ma-laforge/InspectDR.jl/blob/master/src/stylesheets.jl)

You could make your own stylesheet using the sample `getstyle()/setstyle!()` functions in `stylesheets.jl`.

Or you could just manually change the `plot.layout[]/mplot.layout[]` values in your plotting code (example):

```julia-auto
lyt[:halloc_data] = 800
lyt[:valloc_data] = 500

```

and/or

```julia-auto
mplot.layout[:halloc_plot] = 1920
mplot.layout[:valloc_plot] = 1080

```

You will need to pay attention to the points per inch and points to pixel conversion values in the sample code as well, ex:

```julia-auto
ppi = 300
pt2px = ppi/DTPPOINTS_PER_INCH

```

### A quick test for EPS

If you would like to see how the EPS file integrates into LaTeX, you could run one of the demo files in order to quickly generate an output file.

I suggest running `sample/runsamples.jl`, and using the output from demo2: `export_multiplot.eps`.

---

<div class="post-metadata">

### Author: ![BenjaminBorn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/benjaminborn/32/4910_2.png) [@BenjaminBorn](https://discourse.julialang.org/u/BenjaminBorn)
#### Post date: [January 8, 2020, 9:08pm UTC](https://discourse.julialang.org/t/vegalite-jl-size-resolution-of-pdf-output/33021/8 "2020-01-08T21:08:47Z")

</div>

Thanks everyone for the helpful replies. It seems that there is no easy solution to my problem.
