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)
                ┌                                        ┐ 
   [-3.8, -3.6)  1                                       
   [-3.6, -3.4)   0                                       
   [-3.4, -3.2)   0                                       
   [-3.2, -3.0)   0                                       
   [-3.0, -2.8)  1                                       
   [-2.8, -2.6)  3                                      
   [-2.6, -2.4)  4                                      
   [-2.4, -2.2)  3                                      
   [-2.2, -2.0) ██ 6                                     
   [-2.0, -1.8) ███████ 17                               
   [-1.8, -1.6) ███████ 17                               
   [-1.6, -1.4) █████████████ 32                         
   [-1.4, -1.2) █████████████ 33                         
   [-1.2, -1.0) █████████████████████ 51                 
   [-1.0, -0.8) ████████████████████ 49                  
   [-0.8, -0.6) ████████████████████████████████ 77      
   [-0.6, -0.4) ████████████████████████████████ 78      
   [-0.4, -0.2) ████████████████████████████████████  86  
   [-0.2,  0.0) ████████████████████████████ 69          
   [ 0.0,  0.2) ████████████████████████████ 68          
   [ 0.2,  0.4) ████████████████████████████████ 77      
   [ 0.4,  0.6) █████████████████████████ 61             
   [ 0.6,  0.8) █████████████████████████ 62             
   [ 0.8,  1.0) █████████████████████████ 62             
   [ 1.0,  1.2) ███████████████████ 47                   
   [ 1.2,  1.4) █████████████ 33                         
   [ 1.4,  1.6) █████ 14                                 
   [ 1.6,  1.8) ██████ 15                                
   [ 1.8,  2.0) ███ 9                                    
   [ 2.0,  2.2) █████ 13                                 
   [ 2.2,  2.4)  2                                       
   [ 2.4,  2.6) ██ 5                                     
   [ 2.6,  2.8)   0                                       
   [ 2.8,  3.0)  3                                      
   [ 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)

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.