# Can't get a transparent backgound in PlotlyJs

**URL:** <https://discourse.julialang.org/t/cant-get-a-transparent-backgound-in-plotlyjs/88757>\
**Category:** General Usage\
**Tags:** plotlyjs\
**Created:** [October 14, 2022, 10:20pm UTC](https://discourse.julialang.org/t/cant-get-a-transparent-backgound-in-plotlyjs/88757 "2022-10-14T22:20:32Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![1153dent](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1153dent/32/43968_2.png) [@1153dent](https://discourse.julialang.org/u/1153dent)\
**Post date:** [October 14, 2022, 10:20pm UTC](https://discourse.julialang.org/t/cant-get-a-transparent-backgound-in-plotlyjs/88757/1 "2022-10-14T22:20:32Z")

</div>

trying to plot on a transparent background using PlotlyJs not having any luck. Can someone point me in the right direction please?

```julia
using PlotlyJS

make_plot() = plot(scatter(x=1:10, y=rand(10)),
                           Layout(yaxis=attr(showticklabels=false),                 
                                       xaxis=attr(showticklabels=false),
                                      paper_bgcolor="#fff",
                                      plot_bgcolor="#fff",                          
                                     background_color=:transparent,
                                     foreground_color=:black,
                                  ) #layout end

                    )# plot end

[make_plot() make_plot(); make_plot() make_plot()]

```

gets me this.

 ![newplot](https://global.discourse-cdn.com/julialang/original/3X/0/e/0eb26dea2afaf25dd77811e5bc283533b36a26a7.png)

I want to just have a transparent background with no grid lines or background color. Thank you.

---

<div class="post-metadata">

**Author:** ![VivMendes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vivmendes/32/16477_2.png) [@VivMendes](https://discourse.julialang.org/u/VivMendes)\
**Post date:** [October 16, 2022, 1:34am UTC](https://discourse.julialang.org/t/cant-get-a-transparent-backgound-in-plotlyjs/88757/2 "2022-10-16T01:34:51Z")

</div>

The following code will get you a completely white background.

```julia
using PlotlyJS

fig = plot(randn(150))
relayout!(fig, template="simple_white")
fig

```

 ![a](https://global.discourse-cdn.com/julialang/original/3X/4/7/47804ed44176637cdca5d088bb9fefa123b5fa6f.png)

---

<div class="post-metadata">

**Author:** ![1153dent](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1153dent/32/43968_2.png) [@1153dent](https://discourse.julialang.org/u/1153dent)\
**Post date:** [October 16, 2022, 3:23am UTC](https://discourse.julialang.org/t/cant-get-a-transparent-backgound-in-plotlyjs/88757/3 "2022-10-16T03:23:37Z")

</div>

thank you for the kind reply but this is my first time using Plotly. I tried your parameters but it didn’t work

```julia
using PlotlyJS

make_plot() = plot(scatter(x=1:10, y=rand(10)),     
                              Layout(yaxis=attr(showticklabels=false),             
                                     xaxis=attr(showticklabels=false),
                                     template="simple_white",
                                    ) #layout end

                   )# plot end

[make_plot() make_plot(); make_plot() make_plot()]

```

I got the same result as before. What am I doing wrong? Also I see gridlines in your plot can those be made to go away as well?

I tried reading about relayout! and got this  
[https://plotly.com/javascriptplotlyjs-function-reference/#plotlyrelayout](https://plotly.com/javascriptplotlyjs-function-reference/#plotlyrelayout)

thanks for ANY help.

---

<div class="post-metadata">

**Author:** ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)\
**Post date:** [October 16, 2022, 7:49am UTC](https://discourse.julialang.org/t/cant-get-a-transparent-backgound-in-plotlyjs/88757/4 "2022-10-16T07:49:14Z")

</div>

Starting with PlotlyJS, version 0.18, a plot has the default layout template,  
`template= :plotly` (as in your example). It cannot be changed by setting `plot_bgcolor`, but by setting another template.

```julia
make_plot() = plot(scatter(x=1:10, y=rand(10)),     
                   Layout(yaxis_visible=false,         
                          xaxis_visible=false, #showticklabels=false) 
                   )

fig = [make_plot() make_plot(); make_plot() make_plot()]
relayout!(fig, template=:plotly_white)
display(fig)

```

For more details see PlotlyJS.jl docs here: [https://github.com/plotly/plotlyjs.jl-docs/tree/master/julia](https://github.com/plotly/plotlyjs.jl-docs/tree/master/julia).

---

<div class="post-metadata">

**Author:** ![1153dent](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1153dent/32/43968_2.png) [@1153dent](https://discourse.julialang.org/u/1153dent)\
**Post date:** [October 16, 2022, 9:30am UTC](https://discourse.julialang.org/t/cant-get-a-transparent-backgound-in-plotlyjs/88757/5 "2022-10-16T09:30:25Z")

</div>

Hi @empet

I tried your code, thank you for that. But all I got was the plot window for a few second showing some kind of “building” animation using cubes. Then the plot window disappears.

If I run it line by line in the repl I get **completely different behavior** where it works then gets put back to the plot with background ( see below), this is very confusing to a noob.

What am I missing? your code makes sense to me.

**REPL running line by line**

IF I run it line by line in the repl I can “see” the plots after

```julia
fig = [make_plot() make_plot(); make_plot() make_plot()]

```

but they have a blue background

 ![newplot3](https://global.discourse-cdn.com/julialang/original/3X/4/8/48e0a7fb983fc766a3546f9446aa2572ed0a8ba8.png)

Then I run

```julia
relayout!(fig, template=:plotly_white)

```

and I get what I want YAY 🙂

 ![newplot4](https://global.discourse-cdn.com/julialang/original/3X/8/b/8bf62b9a2daa423e89f5c4cb7b446f5d3c753d6e.png)

but then when I run

```julia
 display(fig)

```

I get

 ![newplot3](https://global.discourse-cdn.com/julialang/original/3X/4/8/48e0a7fb983fc766a3546f9446aa2572ed0a8ba8.png)

and it stays UP.

**Running code from CLI ( I am using linux)**

I checked and I am using PlotlyJS v0.18.10

and running this code I get the plot window for a few second showing some kind of “building” animation using cubes. Then the plot window disappears.

```julia
using PlotlyJS

make_plot() = plot(scatter(x=1:10, y=rand(10)),
                   Layout(yaxis_visible=false,xaxis_visible=false, )
                   )

fig = [make_plot() make_plot(); make_plot() make_plot()]
relayout!(fig, template=:plotly_white)
display(fig)

```

what am I doing wrong please?

---

<div class="post-metadata">

**Author:** ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)\
**Post date:** [October 16, 2022, 11:32am UTC](https://discourse.julialang.org/t/cant-get-a-transparent-backgound-in-plotlyjs/88757/6 "2022-10-16T11:32:53Z")

</div>

Usually, I’m running the plotly plots in a Jupyter Notebook, not in REPL. I tested the posted code in a single notebook cell. Even if I move `display(fig)` in the next cell, no fig is displayed after `relayout!`, and the fig preserves the template, `plotly_white`.  
But there is a PlotlyJS issue concerning `relayout!`. If a figure is already displayed just after `relayout`, then running `display(fig)`, too, the default template is reset. As I can remember a user pointed out this issue, here, but not on the PlotlyJS.jl repository, to be considered for fixing.  
Hence no matter where you are running the code above, when you got the right plot, don’t continue with `display(fig)`.  
I’m running Julia 1.7.3 and PlotlyJS, v 0.18.8.

---

<div class="post-metadata">

**Author:** ![1153dent](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1153dent/32/43968_2.png) [@1153dent](https://discourse.julialang.org/u/1153dent)\
**Post date:** [October 16, 2022, 11:53am UTC](https://discourse.julialang.org/t/cant-get-a-transparent-backgound-in-plotlyjs/88757/7 "2022-10-16T11:53:04Z")

</div>

hi there  
thanks so much for sticking with this. Still doesn’t work.

running

```julia
using PlotlyJS

make_plot() = plot(scatter(x=1:10, y=rand(10)),
                   Layout(yaxis_visible=false,xaxis_visible=false, )
                   )

fig = [make_plot() make_plot(); make_plot() make_plot()]
relayout!(fig, template=:plotly_white)

```

**in REPL plot’s the lines but also the background**

 ![newplot6](https://global.discourse-cdn.com/julialang/original/3X/7/6/7636b5b79c3de4b74a60bc6d53e4d3cc3513a787.png)

**running the same code from the cli plots nothing.**

I am running julia Version 1.8.2 (2022-09-29)  
and Plotlyjs PlotlyJS v0.18.10

not sure what to do now as your code makes sense to me. I think what is a little disturbing is that plotting with a transparent background seems to be something that is useful and should work out of the box.

Even when I run @VivMendes code I get

```julia
using PlotlyJS

fig = plot(randn(150))
relayout!(fig, template="simple_white")
fig

```

 ![newplot8](https://global.discourse-cdn.com/julialang/original/3X/d/b/dbf61a0627ea0f147aa57f350b87d4df821df414.png)

so if @VivMendes gets different result AND you do as well then something is wrong my end. The issue is that I haven’t done anything to tweak Plotlyjs. I just installed the PKG.

---

<div class="post-metadata">

**Author:** ![VivMendes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vivmendes/32/16477_2.png) [@VivMendes](https://discourse.julialang.org/u/VivMendes)\
**Post date:** [October 16, 2022, 2:58pm UTC](https://discourse.julialang.org/t/cant-get-a-transparent-backgound-in-plotlyjs/88757/8 "2022-10-16T14:58:56Z")

</div>

Hi @1153dent, you have a point. I forgot about that annoying problem related to (outdated) packages that PlotlyJS needs to spit out the plots in VSCode or Atom. If I run my code in VSCode, I get what you got, plus a massive amount of garbage associated with WebSockets, WebIO, Mux, and Blink.

But if you use Pluto.jl and the package PlutoPlotly.jl (according to @disberd, there is no need to use PlotlyJS directly), you can get what you need. With the precious help of @empet, find below the code that will certainly work in Pluto. I advise you to avoid installing Pluto and PlotlyJS in the same environment because PlotlyJS will deprecate Pluto. If you install Pluto, you do not need to install PlotlyJS. Pluto will install the packages required for the job to be done.

```julia
begin
	using PlutoPlotly

	fig22 = Plot(randn(150), Layout(yaxis_visible = false , xaxis_visible = false))
	relayout!(fig22, hovermode="x", template = "plotly_white")
	p4 = PlutoPlot(fig22)
end

```

 ![a2](https://global.discourse-cdn.com/julialang/original/3X/7/c/7c893600d7be75d2f9aefd7b024954ccc4fb4e7c.png)

and your four panels:

```julia
begin
	make_plot() = Plot(scatter(x=1:10, y=rand(10)),
                   Layout(yaxis_visible = false , xaxis_visible = false )
                   )
	fig10 = [make_plot() make_plot() ; make_plot() make_plot()]
	relayout!(fig10, template = "plotly_white")
	p5 = PlutoPlot(fig10)
end

```

 ![a1](https://global.discourse-cdn.com/julialang/original/3X/e/1/e10970198916a3ff4ca2fbeb2b5d969d12ae82f8.png)

---

<div class="post-metadata">

**Author:** ![1153dent](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1153dent/32/43968_2.png) [@1153dent](https://discourse.julialang.org/u/1153dent)\
**Post date:** [October 16, 2022, 3:13pm UTC](https://discourse.julialang.org/t/cant-get-a-transparent-backgound-in-plotlyjs/88757/9 "2022-10-16T15:13:02Z")

</div>

What OUTSTANDING people you both are. Thank you @VivMendes and @empet for sticking with a poor noob all this time.

I AM going to be using @fonsp Pluto and Plutohooks as my intent is to:

1. populate a Pluto cell with a dataframe that is constantly been updated by a ZMQ pipe.

2. use the dataframe in cell calculations throughout the notebook

3. access the calculations inside the cells using Pluto’s web api to feed other zmq pipes

Your help WILL save me time and effort. OUTSTANDING CHAPS OUTSTANDING.

dent

---

<div class="post-metadata">

**Author:** ![VivMendes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vivmendes/32/16477_2.png) [@VivMendes](https://discourse.julialang.org/u/VivMendes)\
**Post date:** [October 16, 2022, 3:30pm UTC](https://discourse.julialang.org/t/cant-get-a-transparent-backgound-in-plotlyjs/88757/10 "2022-10-16T15:30:11Z")

</div>

My pleasure. I have been in your shoes many times before. I know what it feels to be stuck with a small problem and have a lot of people in the Julia community pop up and take me out of the hook in a minute. By the way, I used Matlab for 25 years, and the mood was quite different there, as far as I can remember.

---

<div class="post-metadata">

**Author:** ![1153dent](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1153dent/32/43968_2.png) [@1153dent](https://discourse.julialang.org/u/1153dent)\
**Post date:** [October 16, 2022, 5:27pm UTC](https://discourse.julialang.org/t/cant-get-a-transparent-backgound-in-plotlyjs/88757/11 "2022-10-16T17:27:56Z")

</div>

I’m a python man myself STRUGGLING to remember all my basic computer science 🙂 Loving reading [bogumils blogs](https://bkamins.github.io/) REALLY helps me and [julia for talented amateurs](https://www.youtube.com/c/juliafortalentedamateurs) especially now he’s covering Pluto 🙂

thanks again for taking time out from your weekend, really helps people like me,
