Can't get a transparent backgound in PlotlyJs

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

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.

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

The following code will get you a completely white background.

using PlotlyJS

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

1 Like

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

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

thanks for ANY help.

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.

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.

1 Like

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

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

but they have a blue background

Then I run

relayout!(fig, template=:plotly_white)

and I get what I want YAY :slight_smile:

but then when I run

 display(fig)

I get

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.

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?

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.

2 Likes

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

running

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

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

using PlotlyJS

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

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.

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.

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

and your four panels:

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

2 Likes

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

2 Likes

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.

1 Like

I’m a python man myself STRUGGLING to remember all my basic computer science :slight_smile: Loving reading bogumils blogs REALLY helps me and julia for talented amateurs especially now he’s covering Pluto :slight_smile:

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

1 Like