Plotting

Author

Marie-Hélène Burle

It can be convenient to plot directly in the REPL (for instance when using SSH).

using UnicodePlots
histogram(randn(1000), nbins=40)
Precompiling UnicodePlots
  ✓ MarchingCubes
  ✓ UnicodePlots
  2 dependencies successfully precompiled in 36 seconds. 42 already precompiled.
Precompiling IntervalSetsExt
  ✓ UnicodePlots → IntervalSetsExt
  1 dependency successfully precompiled in 1 seconds. 46 already precompiled.
Precompiling FreeTypeExt
  ✓ UnicodePlots → FreeTypeExt
  1 dependency successfully precompiled in 2 seconds. 53 already precompiled.
                ┌                                        ┐ 
   [-3.2, -3.0)  1                                       
   [-3.0, -2.8)  1                                       
   [-2.8, -2.6)  2                                       
   [-2.6, -2.4)  3                                      
   [-2.4, -2.2) ███ 7                                    
   [-2.2, -2.0) █████ 13                                 
   [-2.0, -1.8) ██ 6                                     
   [-1.8, -1.6) ██████████ 24                            
   [-1.6, -1.4) ███████████ 27                           
   [-1.4, -1.2) ███████████████ 36                       
   [-1.2, -1.0) ████████████████████ 47                  
   [-1.0, -0.8) ████████████████████ 47                  
   [-0.8, -0.6) █████████████████████ 49                 
   [-0.6, -0.4) █████████████████████████████████ 77     
   [-0.4, -0.2) ████████████████████████████████ 74      
   [-0.2,  0.0) █████████████████████████████████ 77     
   [ 0.0,  0.2) ███████████████████████████████ 73       
   [ 0.2,  0.4) ████████████████████████████████████  83  
   [ 0.4,  0.6) █████████████████████████████████ 78     
   [ 0.6,  0.8) █████████████████████████████ 68         
   [ 0.8,  1.0) ██████████████████ 42                    
   [ 1.0,  1.2) ████████████████████ 47                  
   [ 1.2,  1.4) ████████████████ 39                      
   [ 1.4,  1.6) █████████████ 30                         
   [ 1.6,  1.8) ████████ 20                              
   [ 1.8,  2.0) ███ 8                                    
   [ 2.0,  2.2) ██ 6                                     
   [ 2.2,  2.4) ██ 6                                     
   [ 2.4,  2.6)  3                                      
   [ 2.6,  2.8)  2                                       
   [ 2.8,  3.0)  2                                       
   [ 3.0,  3.2)   0                                       
   [ 3.2,  3.4)  1                                       
   [ 3.4,  3.6)   0                                       
   [ 3.6,  3.8)  1                                       
                └                                        ┘ 
                                 Frequency                 

Most of the time however, you will want to make nicer looking graphs. There are many options to plot in Julia.

Plots is a convenient Julia package which allows to use the same code with several graphing backends such as the GR framework (great for speed), Plotly.js (allows interaction with your graphs in a browser), or PyPlot. The default backend is the GR framework.

StatsPlots is an enhanced version with added stats functionality.

Example:

# First run takes time as the package needs to compile
using StatsPlots
StatsPlots.histogram(randn(1000), bins=40)
Precompiling StatsPlots
  ✓ Arpack_jll
  ✓ Widgets
  ✓ Distances
  ✓ Arpack
  ✓ SentinelArrays
  ✓ Distances → DistancesSparseArraysExt
  ✓ TableOperations
  ✓ Distances → DistancesChainRulesCoreExt
  ✓ MultivariateStats
  ✓ NearestNeighbors
  ✓ Clustering
  ✓ StatsPlots
  12 dependencies successfully precompiled in 8 seconds. 225 already precompiled.

Here, we need to explicitly run StatsPlots.histogram rather than histogram to prevent a conflict with the function of the same name from the package UnicodePlots.