# Change Plots.jl backend dynamically

**URL:** <https://discourse.julialang.org/t/change-plots-jl-backend-dynamically/58240>\
**Category:** Specific Domains\
**Tags:** plotting\
**Created:** [March 30, 2021, 2:54pm UTC](https://discourse.julialang.org/t/change-plots-jl-backend-dynamically/58240 "2021-03-30T14:54:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![HugoTrentesaux](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hugotrentesaux/32/12583_2.png) [@HugoTrentesaux](https://discourse.julialang.org/u/HugoTrentesaux)\
**Post date:** [March 30, 2021, 2:54pm UTC](https://discourse.julialang.org/t/change-plots-jl-backend-dynamically/58240/1 "2021-03-30T14:54:21Z")

</div>

I want to plot a figure using all backends. I do this:

```julia
function plots_all_formats()
    plots("png")
    plots("html")
    plots("svg")
end

```

```julia
function plots(format)
    # load data
    # ...

    if format == "html"
        plotlyjs() # plotlyjs can export interactive plots in html
    elseif format == "svg"
        pyplot() # pyplot has better svg export
    else # gr is the quickest renderer and is perfect for pngs
        gr()
    end
    plot_function(format, data) # makes the plot and pass it to print_output
end

```

```julia
function print_output(path, p, format)
    savefig(p, joinpath(PLOTS_PATH, path*"."*format))
end

```

But it seems that the backend takes some time to change and I do not get reproducible results. Sometimes I get errors like `broken pipe` or `ERROR: only png or svg allowed. got: :html` but it does work when I do it manually in the REPL. Did someone encountered the same problem?

---

<div class="post-metadata">

**Author:** ![jheinen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jheinen/32/2787_2.png) [@jheinen](https://discourse.julialang.org/u/jheinen)\
**Post date:** [March 30, 2021, 3:03pm UTC](https://discourse.julialang.org/t/change-plots-jl-backend-dynamically/58240/2 "2021-03-30T15:03:32Z")

</div>

```julia
elseif format == "svg"
        pyplot() # pyplot has better svg export

```

Just for my understanding: What’s wrong with GR’s SVG export?

---

<div class="post-metadata">

**Author:** ![HugoTrentesaux](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hugotrentesaux/32/12583_2.png) [@HugoTrentesaux](https://discourse.julialang.org/u/HugoTrentesaux)\
**Post date:** [March 30, 2021, 3:19pm UTC](https://discourse.julialang.org/t/change-plots-jl-backend-dynamically/58240/3 "2021-03-30T15:19:00Z")

</div>

It’s quite good but the letters appear in individual groups with their root at the position (0,0) and this is very difficult to modify after with inkscape.

---

<div class="post-metadata">

**Author:** ![jheinen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jheinen/32/2787_2.png) [@jheinen](https://discourse.julialang.org/u/jheinen)\
**Post date:** [April 1, 2021, 6:21pm UTC](https://discourse.julialang.org/t/change-plots-jl-backend-dynamically/58240/4 "2021-04-01T18:21:34Z")

</div>

That’s because the default font is a vector font. If you use `plot(..., font="Times_Roman")` it will work as expected.
