StipplePlotly.jl
StipplePlotly.jl copied to clipboard
Plots integration
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)
Thanks for sharing this, definitely worth digging into it!
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
It's in here.
I guess it's being lazy loaded so you might have to run Plots.plotly() first ?
Confirmed.
You must have PlotlyBase in your project too, and run Plots.plotly().