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.2, -3.0)  1                                       
   [-3.0, -2.8)  1                                       
   [-2.8, -2.6)  4                                      
   [-2.6, -2.4)  3                                      
   [-2.4, -2.2)  3                                      
   [-2.2, -2.0)  4                                      
   [-2.0, -1.8) ████ 11                                  
   [-1.8, -1.6) █████ 13                                 
   [-1.6, -1.4) ██████████████ 35                        
   [-1.4, -1.2) ████████████ 30                          
   [-1.2, -1.0) ████████████████ 40                      
   [-1.0, -0.8) ██████████████████████ 53                
   [-0.8, -0.6) ███████████████████████████ 65           
   [-0.6, -0.4) ████████████████████████████ 68          
   [-0.4, -0.2) ███████████████████████████ 65           
   [-0.2,  0.0) ████████████████████████████████████  86  
   [ 0.0,  0.2) ████████████████████████████████████  86  
   [ 0.2,  0.4) ██████████████████████████████ 72        
   [ 0.4,  0.6) ████████████████████████████ 68          
   [ 0.6,  0.8) ███████████████████████ 57               
   [ 0.8,  1.0) █████████████████████████████ 71         
   [ 1.0,  1.2) ██████████████████  43                    
   [ 1.2,  1.4) ███████████████ 36                       
   [ 1.4,  1.6) ████████████ 31                          
   [ 1.6,  1.8) █████ 12                                 
   [ 1.8,  2.0) █████ 12                                 
   [ 2.0,  2.2) ███ 9                                    
   [ 2.2,  2.4) ██ 6                                     
   [ 2.4,  2.6) ████ 10                                  
   [ 2.6,  2.8)  2                                       
   [ 2.8,  3.0)  1                                       
   [ 3.0,  3.2)  1                                       
   [ 3.2,  3.4)  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.