PlotlyJS vs Plots+plotlyjs()

I like the Plots package together with plotlyjs backend for interactivity. But when compare to pure PlotlyJS package I see some drawbacks.

  • Figure from Plots has defined size and in PlotlyJS the size of the figure changes its size according the window size
  • Plots in heatmap loses the hover info and when zooming the ticks are not updated both is working in pure PlotlyJS package

Is there way how to fix it?

I use pure PlotlyJS instead of Plots. I’ve never have been able to get the PlotlyJS to resize properly. What platform are you on, and what did you do (in other words what sequence of functions and settings did you use) to get this to work?
Many thanks.

1 Like

I get the same behavior (resizing using PlotlyJS but not possible with Plots). So if anyone knows how to address that, that would be great.

@PetrKryslUCSD On my machine (macOS Catalina, Julia 1.5.1) the following code do the trick

julia> using PlotlyJS; # Using PlotlyJS
julia> plot(randn(100)) # ==> The plot changes its size accordingly
julia> using Plots
WARNING: using Plots.plot in module Main conflicts with an existing identifier.
julia> plotlyjs(); # Go to plotlyjs backend
julia> Plots.plot(randn(100)) # The plot does not change its size accordingly to its window

Linux and MacOS

I’m sorry to report that I’ve tried plotting with PlotlyJS both on Windows 10 and in WSL2 (Ubuntu 20.4)
in the hope that I will be able to gracefully resize the plot. It doesn’t work :frowning:

To explain what I was hoping to get (@sglyon will be able to tell me whether or not that is realistic), I wanted to see the figure to resize itself to fill the resized window. That doesn’t happen.


Does this work for any of you?

I got the resizing working to some extent while the program is running using

w = pl.window
ws = size(w)
relayout!(pl, Dict(:width=>ws[1], :height=>ws[2]))

Somehow it doesn’t seem the right way to go though.
Given that it only works while the window is actively controlled from Julia.

The correct solution is not to set the height and width, but to set autosize:

layout = Layout(;autosize = true, 
  xaxis = attr(title="x", range=[0.0, L]), 
  yaxis = attr(title = "F", range=[-1.0, 1.0]))

Then the figure is responsive during the simulation as well as after.


Many thanks. Wan you provide the complete code you use ? In a similar fashion, I tried to use @layout macro (as Layout is unknown with Plots, it is defined in Plotlyjs) but it does not work on my side.

I try this

    using Plots;
    N = 1024;
    x = 0:N-1;
    y = sin.(2π*0.01 .*x);