Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plots fail when used in Pluto notebooks #166

Closed
cncastillo opened this issue May 8, 2023 · 4 comments · Fixed by #195
Closed

Plots fail when used in Pluto notebooks #166

cncastillo opened this issue May 8, 2023 · 4 comments · Fixed by #195
Assignees
Labels

Comments

@cncastillo
Copy link
Member

cncastillo commented May 8, 2023

Apparently the plots need to be fixed in Pluto. Not sure if this is a problem with PlotlyJS and Pluto or if we can fix it somehow.

image

PlutoNotebook.zip

@cncastillo
Copy link
Member Author

cncastillo commented Oct 21, 2023

@beorostica I moved this to high priority, as I believe it is fundamental to be compatible with the language tools.

This can be done creating a new struct that has the Plotly plot inside and define what the show function does.

Like PlutoPlotlyPlot in this file and this HTML example. Or even simpler:

struct PlutoPlotlyPlot
    plot::PlotlyJS.SyncPlot
end

This should be a package extension so it will only be defined if you imported Pluto.

using KomaMRIPlots
p = plot_seq(...) #p::PlotlyJS.SyncPlot

and

using KomaMRIPlots, Pluto
p = plot_seq(...) #p::KomaMRIPlots.PlutoPlotlyPlot

The problem I see with this approach is that we could loose the subplotting functionality p_combined = [p1 p2]. To avoid this we can define what the followting operations do:

https://github.com/JuliaPlots/PlotlyJS.jl/blob/5562c6ca71054cac9c13fcb248e698e3c67b172c/src/util.jl#L7-L10

Base.hcat(sps::SyncPlot...) = SyncPlot(hcat(Plot[sp.plot for sp in sps]...))
Base.vcat(sps::SyncPlot...) = SyncPlot(vcat(Plot[sp.plot for sp in sps]...))
Base.hvcat(rows::Tuple{Vararg{Int}}, sps::SyncPlot...) =
    SyncPlot(hvcat(rows, Plot[sp.plot for sp in sps]...))

So

#Example with hcat
import Base.hcat
Base.hcat(ppps::PlutoPlotlyPlot...) = PlutoPlotlyPlot(hcat([ppp.plot for ppp in ppps]...))

@cncastillo
Copy link
Member Author

cncastillo commented Oct 21, 2023

Just realized that is even easier! someone already did the job for us. PlutoPlotly.jl. We just neet to replace the plot function in the plotting functions to use PlutoPlotly.plot.

@cncastillo
Copy link
Member Author

This is an example that seems to work, just need to do this automatically when in Pluto.

notebook.zip

@cncastillo
Copy link
Member Author

cncastillo commented Oct 22, 2023

I think I fixed it in

Example:
image
notebook (1).zip

@cncastillo cncastillo assigned cncastillo and unassigned beorostica Oct 22, 2023
cncastillo added a commit that referenced this issue Oct 22, 2023
KomaMRIPlots Pluto compatibility #166
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants