Scatterplot with marginal histograms

Here’s a code snippet that created a scatterplot and adds marginal histograms.

using Distributions, Plots, Measures, LaTeXStrings
# set nice fonts and defaults
default(fontfamily = "Computer Modern",titlefont = (14), legend=false, 
            guidefont = (14, :darkgreen), tickfont = (12, :black), 
            framestyle = :box, yminorgrid = true, xminorgrid= true, 
  , dpi=218)

x, y = rand(Normal(), 1000), rand(Normal(), 1000)
layout = @layout [a              _ 
                  b{0.75w,0.75h} c]

plot(layout = layout, link = :both, size = (600, 600))
scatter!(x,y, subplot = 2, framestyle = :box, 
         xlims=(-5,5), ylims=(-5,5), alpha=0.25,
         xlabel=L"\Delta x\,\mathrm{(m)}", ylabel=L"\Delta y\,\mathrm{(m)}")
histogram!([x y], subplot = [1 3], orientation = [:v :h], 
           framestyle = :none, legend=false, bins=-5:0.25:5,
           margin=-12mm, color= :green, alpha=0.5)

Here’s the output:

About PaulNakroshis

Professor of Physics at the University of Southern Maine.
This entry was posted in array, Histograms, Julia, Plots.jl, Plotting and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.