Skip to content

JuliaComputing/PlotlyLight.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build status Codecov

PlotlyLight

PlotlyLight is an ultra-lightweight interface for working with Plotly.js.



✨ Features



🚀 Quickstart

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



📈 Traces

  • 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)



📄 Saving Plots

Saving Plots As HTML

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")



🎛️ Presets

Theme Presets

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!()

Source Presets

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.



⚙️ Settings

Occasionally presets 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.