@VivMendes you can now use PlutoPlotly.jl as replacement for PlotlyJS or PlotlyBase when directly working in Pluto.
This package basically creates a custom struct PlutoPlot
that takes a Plot
object from PlotlyBase/PlotlyJS as input and displays nicely and efficiently inside Pluto.
By using PlutoPlotly that is also in the General Registry, you don’t have to rely on pasting the original plotly hack
from some time back on discourse, which is also quite outdated at the moment
The package also exports a function that can force MathJax in Pluto to cache fonts locally, fixing the problem with latex not showing correctly from plolty inside Pluto.
That is not enabled by default, so if you want to use LaTeX you have to create a cell with the code force_pluto_mathjax_local(true)
.
Here is a picture of your example working almost unmodified inside a Pluto notebook:
And here is the notebook code for direct pasting for testing:
# ╔═╡ 403d5270-af5e-11ec-02ab-71b6376887cc
begin
using PlutoPlotly
using LaTeXStrings
end
# ╔═╡ 97c1c5d1-da17-4f00-8882-b72dcbba30b4
force_pluto_mathjax_local(true)
# ╔═╡ 705007d9-99c8-483c-900f-cab4e9682dc0
begin
f(c,σ) = (-1 + c^(1-σ))/(1-σ)
x=1:15
σ = [0.1, 0.4, 0.8, 0.99, 1.5]
label = [L"\sigma=0.1", L"\sigma=0.4", L"\sigma=0.8", L"\sigma=1", L"\sigma=1.5"]
fig = Plot(Layout(width=700, legend=attr( x=0.35, y=0.95),
xaxis_title="Consumption",
yaxis_title="Utility"))
for (k, s) in enumerate(σ)
addtraces!(fig, scatter(x=x, y=f.(x, s), hovertemplate="consumption: %{x}<br>utility: %{y:.2f}<extra></extra>",
name=label[k], mode="lines"))
end
PlutoPlot(fig)
end