Getting started with Plotly in Julia

Getting Started with Plotly for Julia.

The PlotlyJS Julia library is an interactive, open-source plotting library that supports over 40 unique chart types covering a wide range of statistical, financial, geographic, scientific, and 3-dimensional use-cases.

Built on top of the Plotly JavaScript library (plotly.js), PlotlyJS enables Julia users to create beautiful interactive web-based visualizations that can be displayed in Jupyter notebooks, saved to standalone HTML files, or served as part of pure Julia-built web applications using Dash.jl.

Thanks to deep integration with our Kaleido image export utility, PlotlyJS also provides great support for non-web contexts including desktop editors (e.g. QtConsole, Spyder, PyCharm) and static document publishing (e.g. exporting notebooks to PDF with high-quality vector images).

This Getting Started guide explains how to install PlotlyJS and related optional pages. Once you've installed, you can use our documentation in three main ways:

For information on using Julia to build web applications containing plotly figures, see the Dash User Guide.

We also encourage you to join the Plotly Community Forum if you want help with anything related to plotly.


To install PlotlyJS.jl, open up a Julia REPL, press ] to enter package mode and type:

(v1.6) pkg> add PlotlyJS

For existing users you can run up PlotlyJS from the package manager REPL mode to get the latest release. If after doing this plots do not show up in your chosen frontend, please run build PlotlyJS (again from pkg REPL mode) to tell Julia to download the latest release of the plotly.js javascript library.

Once installation is complete, you are ready to create beautiful plotly.js powered charts!

Basic Usage

using PlotlyJS

p = plot(rand(10, 4))

If you are working at the Julia REPL, a dedicated plotting window (powered by electron and driven by Blink.jl) will be used to display your plot. If you are working in a Jupyter notebook or Jupyter lab, the plot will appear inline.

If instead, you would like to save the chart for external viewing you can do so using the savefig(p, filename::String) method. The type of file will be inferred from the extension on the filename (e.g. myplot.pdf will produce a pdf, while yourplot.html will produce a standalone html file).

Optional Dependencies

PlotlyJS makes use of Requires.jl to build optional integrations with other parts of the Julia package ecosystem. These optional dependencies include:

  • DataFrames.jl: A widely used implementation of the DataFrame standard for tabular data in Julia. The PlotlyJS.jl integration with DataFrames is deep, yet elegant. By implementing a method plot(::DataFrame, args...; kwargs...), PlotlyJS.jl obtains many advanced functionalities present in other libraries, such as from the python library. Many examples throughout the documentation here use this method for the plot function.

  • CSV.jl: The de-facto standard for reading csv data files in Julia. After importing PlotlyJS and CSV, a dataset(dataset_name::String) function is defined that can load a handful of datasets commonly used in plotting examples. If you have also loaded DataFrames, an additional dataset(DataFrame, dataset_name::String) method is defined that will automatically load the desired dataset into a DataFrame

  • IJulia.jl: The Jupyter kernel implementation for Julia. If you use jupyter notebooks (or Jupyter lab!), PlotlyJS.jl will be ready to go right out of the box thanks to our integration with IJulia

  • Distributions.jl: The canonical way to represent and work with probability distributions in Julia. The integration with Distributions.jl adds the method plot(d::ContinuousUnivariateDistribution) to quickly and easily view the pdf of the distribution d. Appropriate ranges are automatically selected based on the quantiles of the distribution.

  • Colors.jl: A very feature complete library for representing and working with colors in Julia. Anywhere plotly.js accepts a color (for example marker.color, or marker.line.color, layout.title.font.color, etc.) Julia users can also pass an instance of any type from the Colors.jl library. This

  • ColorSchemes.jl: a collection of over 800 ready to use color schemes. All schemes from the ColorSchemes.jl package are ready to be used. They are all exposed under the colors object that is imported when you run using PlotlyJS. To access the vidiris colorscheme you would use colors.viridis. If you aren't sure which color scheme you'd like to use, you can use tab completion to inspect the many available color schemes. The colors object also has helpful categorizations of families of color schemes such as colors.sequential, colors.diverging, colors.cyclical and colors.discrete. Most often, a color scheme is used to define the layout.coloraxis.colorscale property.

To use any of these optional integrations, all you need to do is import both PlotlyJS and the desired package in your Julia code.

For example:

using PlotlyJS
using CSV, DataFrames  # automatically loads these integrations

df = dataset(DataFrame, "tips")
plot(df, y=:tip, facet_row=:sex, facet_col=:smoker, color=:day, kind="violin")

Where to next?

Once you've installed, you can use our documentation in two main ways:

  1. Jump right in to and see examples of how to make basic charts, statistical charts, scientific charts, financial charts, and 3-dimensional charts.

  2. Read through our documentation on the fundamentals of using plotly from Julia.

  3. Check out our exhaustive reference guide, the Figure Reference

For information on using Julia to build web applications containing plotly figures, see the Dash User Guide.

We also encourage you to join the Plotly Community Forum if you want help with anything related to plotly.