-
Notifications
You must be signed in to change notification settings - Fork 85
/
11_1_carpet_line_scatter_plots.fsx
168 lines (121 loc) · 4.42 KB
/
11_1_carpet_line_scatter_plots.fsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
(**
---
title: Carpet line and scatter plots
category: Carpet Plots
categoryindex: 12
index: 1
---
*)
(*** hide ***)
(*** condition: prepare ***)
#r "nuget: Newtonsoft.JSON, 13.0.1"
#r "nuget: DynamicObj, 2.0.0"
#r "../src/Plotly.NET/bin/Release/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](https://en.wikipedia.org/wiki/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.
## 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***)