PlotlyLight is an ultra-lightweight interface for working with Plotly.js.
- 🚀 Fastest time-to-first-plot in Julia!
- 🌐 Use the Plotly.js Javascript documentation directly. No magic syntax: Just
JSON3.write
. - 📂 Set deeply-nested keys easily, e.g.
myplot.layout.xaxis.title.font.family = "Arial"
. - 📊 The Same built-in themes as Plotly's python package.
using PlotlyLight
preset.template.plotly_dark!() # Change template
p = plot(x = 1:20, y = cumsum(randn(20)), type="scatter", mode="lines+markers") # Make plot
p.layout.title.text = "My Title!" # Make changes
p # `display(p)` to see the updated plot
- A core concept in Plotly is that of a trace, which is the data along with specifications on how to plot it.
- There are many different trace types (e.g. "scatter" for scatterplots, "box" for boxplots).
PlotlyLight does some simple "tricks" with the plot
function so that:
plot.trace(; kw...) == plot(; type=trace, kw...)
This lets you tab-autocomplete the trace type:
julia> plot.<TAB>
# bar barpolar box candlestick
# carpet choropleth choroplethmapbox cone
# contour contourcarpet densitymapbox funnel
# funnelarea heatmap heatmapgl histogram
# histogram2d histogram2dcontour icicle image
# indicator isosurface mesh3d ohlc
# parcats parcoords pie pointcloud
# sankey scatter scatter3d scattercarpet
# scattergeo scattergl scattermapbox scatterpolar
# scatterpolargl scattersmith scatterternary splom
# streamtube sunburst surface table
# treemap violin volume waterfall
You can chain the dot syntax to add traces to a plot, e.g.
y = randn(20)
plot.bar(; y).scatter(; y)
p = plot(y=rand(10))
PlotlyLight.save(p, "myplot.html")
- Note: call
preset.source.standalone!()
first if you want the html file to contain the entire plotly.js script. This enables you to view the plot even without internet access.
Save Plots as Image via PlotlyKaleido.jl
using PlotlyKaleido
PlotlyKaleido.start()
(;data, layout, config) = p
PlotlyKaleido.savefig((; data, layout, config), "myplot.png")
Set a theme/template via preset.template.<option>!()
. Note that options are tab-autocomplete-able. These are borrowed from the built-in themes in the plotly python package.
preset.template.ggplot2!()
Change how the plotly.js script gets loaded in the produced html via preset.source.<option>!()
.
preset.source.none!() # Don't include the script.
preset.source.cdn!() # Use the official plotly.js CDN.
preset.source.local!() # Use a local version of the plotly.js script.
preset.source.standalone!() # Copy-paste the plotly.js script into the html output.
Occasionally preset
s aren't enough. Lower level user-configurable settings are available in PlotlyLight.settings
:
PlotlyLight.settings.src::Cobweb.Node # plotly.js script loader
PlotlyLight.settings.div::Cobweb.Node # The plot-div
PlotlyLight.settings.layout::EasyConfig.Config # default `layout` for all plots
PlotlyLight.settings.config::EasyConfig.Config # default `config` for all plots
PlotlyLight.settings.reuse_preview::Bool # In the REPL, open plots in same page (true, the default) or different pages.
Check out e.g. PlotlyLight.Settings().src
to examine default values.