StipplePlotly.jl icon indicating copy to clipboard operation
StipplePlotly.jl copied to clipboard

Plots integration

Open PhilipVinc opened this issue 4 years ago • 5 comments

With some painful reverse engineering, I realised that we can use Plots.jl to integrate with StripplePlotly with the following:

using Mesurements
using Plots

function to_plotly_base(pl)
  pl = Plots.plotlybase_syncplot(pl)
  delete!(pl.layout.fields, :height)
  delete!(pl.layout.fields, :width)
  pl.layout.fields[:margin] = Dict(:l=>50, :b=>50, :r=>50, :t=>60)
  return pl
end

# generate data with errors
y = Measurements.measurement(rand(10), rand(10)*0.1)

# use recipes from plots.jl
plt = plot(1:10, y)

# this object now is a PlotlyBase.Plot and can be used with Stripple
plt = to_plotly_base(plt)

# update the model
model.plot_data[] = plt.data
model.plot_layout[] = plt.layout

It would be nice if this could be done automatically.

(The margins are the default from PlotlyBase, because the default from Plots jl get cropped when using them with stripple)

PhilipVinc avatar Apr 12 '21 08:04 PhilipVinc

Thanks for sharing this, definitely worth digging into it!

essenciary avatar Apr 12 '21 09:04 essenciary

PlotlyJS.jl are wrap of PlotlyBase.jl. The good is that the data and layout fields from PlotlyBase behave same as they do in plot of StipplePlotly.

BTW: I cannot find Plots.plotlybase_syncplot .

julia> using Plots

julia> Plots.plotlybase_syncplot
ERROR: UndefVarError: plotlybase_syncplot not defined

touchft avatar Apr 12 '21 10:04 touchft

It's in here. I guess it's being lazy loaded so you might have to run Plots.plotly() first ?

PhilipVinc avatar Apr 12 '21 10:04 PhilipVinc

Confirmed. You must have PlotlyBase in your project too, and run Plots.plotly().

PhilipVinc avatar Apr 12 '21 10:04 PhilipVinc