// can't yet format YamlFrontmatter (["title: Carpet line and scatter plots"; "category: Carpet Plots"; "categoryindex: 12"; "index: 1"], Some { StartLine = 2 StartColumn = 0 EndLine = 6 EndColumn = 8 }) to pynb markdown

In [ ]:
#r "nuget: Plotly.NET, 2.0.0-preview.16"
#r "nuget: Plotly.NET.Interactive, 2.0.0-preview.16"

Carpet charts

BinderScriptNotebook

Summary: This example shows how to create carpet charts in F#.

let's first create some data for the purpose of creating example charts:

In [3]:
open Plotly.NET 
  
//carpet coordinate data
let a = [4.; 4.; 4.; 4.5; 4.5; 4.5; 5.; 5.; 5.; 6.; 6.; 6.]
let b = [1.; 2.; 3.; 1.; 2.; 3.; 1.; 2.; 3.; 1.; 2.; 3.]
let y = [2.; 3.5; 4.; 3.; 4.5; 5.; 5.5; 6.5; 7.5; 8.; 8.5; 10.]

//carpet plot data
let aData = [4.; 5.; 5.; 6.]
let bData = [1.; 1.; 2.; 3.]
let sizes = [5; 10; 15; 20]

A carpet plot is any of a few different specific types of plot. The more common plot referred to as a carpet plot is one that illustrates the interaction between two or more independent variables and one or more dependent variables in a two-dimensional plot.

Besides the ability to incorporate more variables, another feature that distinguishes a carpet plot from an equivalent contour plot or 3D surface plot is that a carpet plot can be used to more accurately interpolate data points.

A conventional carpet plot can capture the interaction of up to three independent variables and three dependent variables and still be easily read and interpolated.

Carpet plots have common applications within areas such as material science for showing elastic modulus in laminates,and within aeronautics.

A carpet plot with two independent variables and one dependent variable is often called a cheater plot for the use of a phantom "cheater" axis instead of the horizontal axis.

(https://en.wikipedia.org/wiki/Carpet_plot)

Carpet Traces

In plotly, carpet plots are different to all other trace types in the regard that the coordinate system of the carpet is not set on the layout, but is itself a trace.

Use Chart.Carpet to define these coordinate traces. All carpets have a mandatory identifier, which will be used by other traces to define which carpet coordinate system to use.

In [4]:
let carpet = Chart.Carpet("carpetIdentifier", A = a, B = b, Y = y)
In [ ]:
carpet
Out[ ]:

Carpet point charts

use Chart.PointCarpet to create a point plot on the referenced carpet coordinate system:

In [6]:
let carpetPoint = 
    [
        carpet
        Chart.PointCarpet(aData,bData,"carpetIdentifier", Name = "Point")
    ]
    |> Chart.combine
In [ ]:
carpetPoint
Out[ ]:

Carpet line charts

use Chart.LineCarpet to create a line plot on the referenced carpet coordinate system:

In [8]:
let carpetLine = 
    [
        carpet
        Chart.LineCarpet(aData,bData,"carpetIdentifier",Name = "Line")
    ]
    |> Chart.combine
In [ ]:
carpetLine
Out[ ]:

Carpet Spline charts

use Chart.LineCarpet to create a spline plot on the referenced carpet coordinate system:

In [10]:
let carpetSpline = 
    [
        carpet
        Chart.SplineCarpet(aData,bData,"carpetIdentifier",Name = "Spline")
    ]
    |> Chart.combine
In [ ]:
carpetSpline
Out[ ]:

Carpet bubble charts

use Chart.LineCarpet to create a bubble plot on the referenced carpet coordinate system:

In [12]:
let carpetBubble = 
    [
        carpet
        Chart.BubbleCarpet((Seq.zip3 aData bData sizes),"carpetIdentifier",Name = "Bubble")
    ]
    |> Chart.combine
In [ ]:
carpetBubble
Out[ ]: