Wolfram Research

Function Repository Resource:

MarginalPlot (1.0.0) current version: 1.1.0 »

Source Notebook

Plot 2D data together with histograms of the marginal distributions

Contributed by: Jon McLoone

ResourceFunction["MarginalPlot"][data]

produces a ListPlot of 2D data together with histograms of the marginal distributions.

ResourceFunction["MarginalPlot"][data,binspec]

uses the bin specification binspec.

Details and Options

ResourceFunction["MarginalPlot"] supports options of Graphics with the following additions:
"HistogramScale"0.3proportion of space provided for histograms
"HistogramOptions"{}list of any options supported by Histogram

Examples

Basic Examples (2) 

See the marginal distributions of a hundred random points:

In[1]:=
ResourceFunction["MarginalPlot"][RandomReal[1, {100, 2}]]
Out[1]=

See the marginal distributions of 2D data together with the data:

In[2]:=
ResourceFunction["MarginalPlot"][
 RandomVariate[BinormalDistribution[{-1, 1}, {1, 2}, 0.7], 500]]
Out[2]=

Scope (2) 

Specify the number of bins:

In[3]:=
data = RandomVariate[BinormalDistribution[{-1, 1}, {1, 2}, 0.7], 500];
ResourceFunction["MarginalPlot"][data, 40]
Out[4]=

Specify the bin widths:

In[5]:=
ResourceFunction["MarginalPlot"][data, {1}]
Out[5]=

Options (3) 

The proportion of the plot space occupied by the Histogram elements is controlled by "HistogramScale":

In[6]:=
data = RandomVariate[BinormalDistribution[{-1, 1}, {1, 2}, 0.7], 500];
ResourceFunction["MarginalPlot"][data, "HistogramScale" -> 0.05]
Out[7]=

Create larger histograms:

In[8]:=
ResourceFunction["MarginalPlot"][data, "HistogramScale" -> 0.5]
Out[8]=

Standard Graphics options are supported:

In[9]:=
ResourceFunction["MarginalPlot"][data, AspectRatio -> 0.5]
Out[9]=

All standard options for Histogram are supported and must be passed in using the option "HistogramOptions":

In[10]:=
ResourceFunction["MarginalPlot"][
 RandomVariate[BinormalDistribution[{-1, 1}, {1, 2}, 0.7], 500], "HistogramOptions" -> {ChartElementFunction -> "GradientScaleRectangle"}]
Out[10]=

Publisher

Jon McLoone

Version History

  • 1.1.0 – 22 February 2023
  • 1.0.0 – 01 July 2022

Related Resources

License Information