Skip to content

Add full carpet trace/layout support #201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Sep 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Plotly.NET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{7B09CC0A-F
docs\09_2_sankey.fsx = docs\09_2_sankey.fsx
docs\10_0_ternary_line_scatter_plots.fsx = docs\10_0_ternary_line_scatter_plots.fsx
docs\10_1_styling_ternary_layouts.fsx = docs\10_1_styling_ternary_layouts.fsx
docs\11_1_carpet_line_scatter_plots.fsx = docs\11_1_carpet_line_scatter_plots.fsx
docs\11_2_contourcarpet_plots.fsx = docs\11_2_contourcarpet_plots.fsx
docs\_template.fsx = docs\_template.fsx
docs\_template.html = docs\_template.html
docs\_template.ipynb = docs\_template.ipynb
Expand Down
6 changes: 3 additions & 3 deletions docs/10_0_ternary_line_scatter_plots.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ Ternary plots are tools for analyzing compositional data in the three-dimensiona
use `Chart.PointTernary` to create a ternary plot that displays points on a ternary coordinate system:
*)

let ternaryPolar = Chart.PointTernary(a,b,c)
let ternaryPoint = Chart.PointTernary(a,b,c)
(*** condition: ipynb ***)
#if IPYNB
ternaryPolar
ternaryPoint
#endif // IPYNB

(***hide***)
ternaryPolar |> GenericChart.toChartHTML
ternaryPoint |> GenericChart.toChartHTML
(***include-it-raw***)

(**
Expand Down
168 changes: 168 additions & 0 deletions docs/11_1_carpet_line_scatter_plots.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
(**
---
title: Carpet line and scatter plots
category: Carpet Plots
categoryindex: 12
index: 1
---
*)

(*** hide ***)

(*** condition: prepare ***)
#r "nuget: Newtonsoft.JSON, 12.0.3"
#r "nuget: DynamicObj"
#r "../bin/Plotly.NET/netstandard2.0/Plotly.NET.dll"

(*** condition: ipynb ***)
#if IPYNB
#r "nuget: Plotly.NET, {{fsdocs-package-version}}"
#r "nuget: Plotly.NET.Interactive, {{fsdocs-package-version}}"
#endif // IPYNB

(**
# Carpet charts

[![Binder]({{root}}img/badge-binder.svg)](https://mybinder.org/v2/gh/plotly/Plotly.NET/gh-pages?filepath={{fsdocs-source-basename}}.ipynb) 
[![Script]({{root}}img/badge-script.svg)]({{root}}{{fsdocs-source-basename}}.fsx) 
[![Notebook]({{root}}img/badge-notebook.svg)]({{root}}{{fsdocs-source-basename}}.ipynb)

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

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

*)

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.
*)

let carpet = Chart.Carpet("carpetIdentifier", A = a, B = b, Y = y)

(*** condition: ipynb ***)
#if IPYNB
carpet
#endif // IPYNB

(***hide***)
carpet |> GenericChart.toChartHTML
(***include-it-raw***)

(**
## Carpet point charts

use `Chart.PointCarpet` to create a point plot on the referenced carpet coordinate system:
*)
let carpetPoint =
[
carpet
Chart.PointCarpet(aData,bData,"carpetIdentifier", Name = "Point")
]
|> Chart.combine

(*** condition: ipynb ***)
#if IPYNB
carpetPoint
#endif // IPYNB

(***hide***)
carpetPoint |> GenericChart.toChartHTML
(***include-it-raw***)

(**
## Carpet line charts

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

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

(*** condition: ipynb ***)
#if IPYNB
carpetLine
#endif // IPYNB

(***hide***)
carpetLine |> GenericChart.toChartHTML
(***include-it-raw***)

(**
## Carpet Spline charts

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

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

(*** condition: ipynb ***)
#if IPYNB
carpetSpline
#endif // IPYNB

(***hide***)
carpetSpline |> GenericChart.toChartHTML
(***include-it-raw***)

(**
## Carpet bubble charts

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

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

(*** condition: ipynb ***)
#if IPYNB
carpetBubble
#endif // IPYNB

(***hide***)
carpetBubble |> GenericChart.toChartHTML
(***include-it-raw***)




74 changes: 74 additions & 0 deletions docs/11_2_contourcarpet_plots.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
(**
---
title: Contour carpet plots
category: Carpet Plots
categoryindex: 12
index: 2
---
*)

(*** hide ***)

(*** condition: prepare ***)
#r "nuget: Newtonsoft.JSON, 12.0.3"
#r "nuget: DynamicObj"
#r "../bin/Plotly.NET/netstandard2.0/Plotly.NET.dll"

(*** condition: ipynb ***)
#if IPYNB
#r "nuget: Plotly.NET, {{fsdocs-package-version}}"
#r "nuget: Plotly.NET.Interactive, {{fsdocs-package-version}}"
#endif // IPYNB

(**
# Contour carpet charts

[![Binder]({{root}}img/badge-binder.svg)](https://mybinder.org/v2/gh/plotly/Plotly.NET/gh-pages?filepath={{fsdocs-source-basename}}.ipynb) 
[![Script]({{root}}img/badge-script.svg)]({{root}}{{fsdocs-source-basename}}.fsx) 
[![Notebook]({{root}}img/badge-notebook.svg)]({{root}}{{fsdocs-source-basename}}.ipynb)

*Summary:* This example shows how to create contour plots on carpets in F#.

*)

open Plotly.NET
open Plotly.NET.LayoutObjects

let contourCarpet =
[
Chart.Carpet(
"contour",
A = [0.; 1.; 2.; 3.; 0.; 1.; 2.; 3.; 0.; 1.; 2.; 3.],
B = [4.; 4.; 4.; 4.; 5.; 5.; 5.; 5.; 6.; 6.; 6.; 6.],
X = [2.; 3.; 4.; 5.; 2.2; 3.1; 4.1; 5.1; 1.5; 2.5; 3.5; 4.5],
Y = [1.; 1.4; 1.6; 1.75; 2.; 2.5; 2.7; 2.75; 3.; 3.5; 3.7; 3.75],
AAxis = LinearAxis.initCarpet(
TickPrefix = "a = ",
Smoothing = 0.,
MinorGridCount = 9,
AxisType = StyleParam.AxisType.Linear
),
BAxis = LinearAxis.initCarpet(
TickPrefix = "b = ",
Smoothing = 0.,
MinorGridCount = 9,
AxisType = StyleParam.AxisType.Linear
)
)
Chart.ContourCarpet(
"contour",
[1.; 1.96; 2.56; 3.0625; 4.; 5.0625; 1.; 7.5625; 9.; 12.25; 15.21; 14.0625],
A = [0; 1; 2; 3; 0; 1; 2; 3; 0; 1; 2; 3],
B = [4; 4; 4; 4; 5; 5; 5; 5; 6; 6; 6; 6]
)
]
|> Chart.combine

(*** condition: ipynb ***)
#if IPYNB
contourCarpet
#endif // IPYNB

(***hide***)
contourCarpet |> GenericChart.toChartHTML
(***include-it-raw***)
2 changes: 1 addition & 1 deletion src/Plotly.NET/ChartAPI/Chart.fs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ type Chart =
?MultiOpacity = MultiOpacity,
?Pattern = Pattern,
?Symbol = Symbol ,
?MultiSymbols = MultiSymbols ,
?MultiSymbol = MultiSymbols ,
?OutlierColor = OutlierColor ,
?Maxdisplayed = Maxdisplayed ,
?ReverseScale = ReverseScale ,
Expand Down
Loading