Some Visualization Libraries to Choose From

A quick reference on the many options to visualize data with Julia.

by Martin D. Maas, Ph.D

@MartinDMaas

Last updated: 2021-08-02

Displaying 2D Arrays in Julia using a Plots.jl Heatmap

There are multiple plotting packages for Julia worth checking:

Package Description Examples Tutorial
Plots.jl provides a single API to access multiple “backends”, which inlclude Matplotlib (Pyplot), Plotly, and GR. Pyplot, Plotly, GR. Docs
StatsPlots.jl A drop-in replacement for Plots.jl that contains specialized statistical plotting functionalities. StatsPlots.jl repository Plots.jl docs
Makie.jl A high-performance plotting ecosystem with OpenGL, Cairo and WebGL backends. It’s great for publication-quality plotting, but can be a little bit slow to load and use Docs
VegaLite A Julia wrapper for the Vega-Lite library. Great for interactive graphics. Docs.
Gadfly Based on the R package gglot2, very well suited for statistics and machine learning. Docs

Detailed documentation can be found in each package, and in the referenced tutorials and examples pages.

To keep this tutorial series as much as self-contained as reasonably possible, let’s go over a few examples here:

Plotting a Function with Plots.jl

using Plots

# 10 points of random data, in two columns
x = 1:10; 
y = rand(10, 2); 

plot(x, y, title = "Two Lines", label = ["Line 1" "Line 2"], marker = ([:hex :d], 8), lw = 3)
xlabel!("My x label")

Julia Line Plot

Displaying a Pseudocolor Plot of a 2D Array

One way of doing a 2d pseudocolor plot with Julia is to use the ‘heatmap’ function.

using Plots

# Generate some 2D data
x = LinRange(-1,1,100);
Z = zeros(100,100)
for i=1:100, j=1:100
    r =  x[i]^2 + x[j]^2
    Z[i,j] = sin(10*r) / (1+r)
end

heatmap(Z)

Julia Heatmap

Calling Matplotlib’s PyPlot with PyPlot.jl

Alternatively, we could also use the PyPlot package, which provides a direct interface to Matplotlib’s Pyplot via PyCall, namely to the matplotlib.pyplot module.

For example, the above example can be modified as follows:

using PyPlot    # Replace Plots with PyPlot
pcolormesh(Z)   # Replace heatmap with pcolormesh

to produce the following plot:

Julia Pseudolocor Plot

Note that using both PyPlot and Plots could result in errors, so native Julia libraries should be preferred.