Adapting code from Plots into PlotlyJS

This is a PlotlyJS version of your code:

using PlotlyJS
using LaTeXStrings
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 
display(fig)
4 Likes