|
| 1 | +(** |
| 2 | +--- |
| 3 | +title: Carpet line and scatter plots |
| 4 | +category: Carpet Plots |
| 5 | +categoryindex: 12 |
| 6 | +index: 1 |
| 7 | +--- |
| 8 | +*) |
| 9 | + |
| 10 | +(*** hide ***) |
| 11 | + |
| 12 | +(*** condition: prepare ***) |
| 13 | +#r "nuget: Newtonsoft.JSON, 12.0.3" |
| 14 | +#r "nuget: DynamicObj" |
| 15 | +#r "../bin/Plotly.NET/netstandard2.0/Plotly.NET.dll" |
| 16 | + |
| 17 | +(*** condition: ipynb ***) |
| 18 | +#if IPYNB |
| 19 | +#r "nuget: Plotly.NET, {{fsdocs-package-version}}" |
| 20 | +#r "nuget: Plotly.NET.Interactive, {{fsdocs-package-version}}" |
| 21 | +#endif // IPYNB |
| 22 | + |
| 23 | +(** |
| 24 | +# Carpet charts |
| 25 | +
|
| 26 | +[](https://mybinder.org/v2/gh/plotly/Plotly.NET/gh-pages?filepath={{fsdocs-source-basename}}.ipynb)  |
| 27 | +[]({{root}}{{fsdocs-source-basename}}.fsx)  |
| 28 | +[]({{root}}{{fsdocs-source-basename}}.ipynb) |
| 29 | +
|
| 30 | +*Summary:* This example shows how to create carpet charts in F#. |
| 31 | +
|
| 32 | +let's first create some data for the purpose of creating example charts: |
| 33 | +
|
| 34 | +*) |
| 35 | + |
| 36 | +open Plotly.NET |
| 37 | + |
| 38 | +//carpet coordinate data |
| 39 | +let a = [4.; 4.; 4.; 4.5; 4.5; 4.5; 5.; 5.; 5.; 6.; 6.; 6.] |
| 40 | +let b = [1.; 2.; 3.; 1.; 2.; 3.; 1.; 2.; 3.; 1.; 2.; 3.] |
| 41 | +let y = [2.; 3.5; 4.; 3.; 4.5; 5.; 5.5; 6.5; 7.5; 8.; 8.5; 10.] |
| 42 | + |
| 43 | +//carpet plot data |
| 44 | +let aData = [4.; 5.; 5.; 6.] |
| 45 | +let bData = [1.; 1.; 2.; 3.] |
| 46 | +let sizes = [5; 10; 15; 20] |
| 47 | + |
| 48 | +(** |
| 49 | +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. |
| 50 | +
|
| 51 | +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. |
| 52 | +
|
| 53 | +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. |
| 54 | +
|
| 55 | +Carpet plots have common applications within areas such as material science for showing elastic modulus in laminates,and within aeronautics. |
| 56 | +
|
| 57 | +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. |
| 58 | +
|
| 59 | +(https://en.wikipedia.org/wiki/Carpet_plot) |
| 60 | +
|
| 61 | +## Carpet Traces |
| 62 | +
|
| 63 | +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. |
| 64 | +
|
| 65 | +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. |
| 66 | +*) |
| 67 | + |
| 68 | +let carpet = Chart.Carpet("carpetIdentifier", A = a, B = b, Y = y) |
| 69 | + |
| 70 | +(*** condition: ipynb ***) |
| 71 | +#if IPYNB |
| 72 | +carpet |
| 73 | +#endif // IPYNB |
| 74 | + |
| 75 | +(***hide***) |
| 76 | +carpet |> GenericChart.toChartHTML |
| 77 | +(***include-it-raw***) |
| 78 | + |
| 79 | +(** |
| 80 | +## Carpet point charts |
| 81 | +
|
| 82 | +use `Chart.PointCarpet` to create a point plot on the referenced carpet coordinate system: |
| 83 | +*) |
| 84 | +let carpetPoint = |
| 85 | + [ |
| 86 | + carpet |
| 87 | + Chart.PointCarpet(aData,bData,"carpetIdentifier", Name = "Point") |
| 88 | + ] |
| 89 | + |> Chart.combine |
| 90 | + |
| 91 | +(*** condition: ipynb ***) |
| 92 | +#if IPYNB |
| 93 | +carpetPoint |
| 94 | +#endif // IPYNB |
| 95 | + |
| 96 | +(***hide***) |
| 97 | +carpetPoint |> GenericChart.toChartHTML |
| 98 | +(***include-it-raw***) |
| 99 | + |
| 100 | +(** |
| 101 | +## Carpet line charts |
| 102 | +
|
| 103 | +use `Chart.LineCarpet` to create a line plot on the referenced carpet coordinate system: |
| 104 | +*) |
| 105 | + |
| 106 | +let carpetLine = |
| 107 | + [ |
| 108 | + carpet |
| 109 | + Chart.LineCarpet(aData,bData,"carpetIdentifier",Name = "Line") |
| 110 | + ] |
| 111 | + |> Chart.combine |
| 112 | + |
| 113 | +(*** condition: ipynb ***) |
| 114 | +#if IPYNB |
| 115 | +carpetLine |
| 116 | +#endif // IPYNB |
| 117 | + |
| 118 | +(***hide***) |
| 119 | +carpetLine |> GenericChart.toChartHTML |
| 120 | +(***include-it-raw***) |
| 121 | + |
| 122 | +(** |
| 123 | +## Carpet Spline charts |
| 124 | +
|
| 125 | +use `Chart.LineCarpet` to create a spline plot on the referenced carpet coordinate system: |
| 126 | +*) |
| 127 | + |
| 128 | +let carpetSpline = |
| 129 | + [ |
| 130 | + carpet |
| 131 | + Chart.SplineCarpet(aData,bData,"carpetIdentifier",Name = "Spline") |
| 132 | + ] |
| 133 | + |> Chart.combine |
| 134 | + |
| 135 | +(*** condition: ipynb ***) |
| 136 | +#if IPYNB |
| 137 | +carpetSpline |
| 138 | +#endif // IPYNB |
| 139 | + |
| 140 | +(***hide***) |
| 141 | +carpetSpline |> GenericChart.toChartHTML |
| 142 | +(***include-it-raw***) |
| 143 | + |
| 144 | +(** |
| 145 | +## Carpet bubble charts |
| 146 | +
|
| 147 | +use `Chart.LineCarpet` to create a bubble plot on the referenced carpet coordinate system: |
| 148 | +*) |
| 149 | + |
| 150 | +let carpetBubble = |
| 151 | + [ |
| 152 | + carpet |
| 153 | + Chart.BubbleCarpet((Seq.zip3 aData bData sizes),"carpetIdentifier",Name = "Bubble") |
| 154 | + ] |
| 155 | + |> Chart.combine |
| 156 | + |
| 157 | +(*** condition: ipynb ***) |
| 158 | +#if IPYNB |
| 159 | +carpetBubble |
| 160 | +#endif // IPYNB |
| 161 | + |
| 162 | +(***hide***) |
| 163 | +carpetBubble |> GenericChart.toChartHTML |
| 164 | +(***include-it-raw***) |
| 165 | + |
| 166 | + |
| 167 | + |
| 168 | + |
0 commit comments