Skip to content

Commit cafdf2c

Browse files
committed
#385: add marker styling docs
1 parent 8366cad commit cafdf2c

File tree

1 file changed

+166
-0
lines changed

1 file changed

+166
-0
lines changed

docs/general/styling-markers.fsx

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
(**
2+
---
3+
title: Styling Markers
4+
category: General
5+
categoryindex: 1
6+
index: 9
7+
---
8+
*)
9+
10+
(*** hide ***)
11+
12+
(*** condition: prepare ***)
13+
#r "nuget: Newtonsoft.JSON, 13.0.1"
14+
#r "nuget: DynamicObj, 2.0.0"
15+
#r "nuget: Giraffe.ViewEngine.StrongName, 2.0.0-alpha1"
16+
#r "../../src/Plotly.NET/bin/Release/netstandard2.0/Plotly.NET.dll"
17+
18+
Plotly.NET.Defaults.DefaultDisplayOptions <-
19+
Plotly.NET.DisplayOptions.init (PlotlyJSReference = Plotly.NET.PlotlyJSReference.NoReference)
20+
21+
(*** condition: ipynb ***)
22+
#if IPYNB
23+
#r "nuget: Plotly.NET, {{fsdocs-package-version}}"
24+
#r "nuget: Plotly.NET.Interactive, {{fsdocs-package-version}}"
25+
#endif // IPYNB
26+
27+
(**
28+
[![Binder]({{root}}img/badge-binder.svg)](https://mybinder.org/v2/gh/plotly/plotly.net/gh-pages?urlpath=/tree/home/jovyan/{{fsdocs-source-basename}}.ipynb)&emsp;
29+
[![Notebook]({{root}}img/badge-notebook.svg)]({{root}}{{fsdocs-source-basename}}.ipynb)
30+
31+
# Styling Markers
32+
33+
#### Table of contents
34+
- [Basics](#Basics)
35+
- [Marker Symbols](#Marker-Symbols)
36+
- [2D Marker Symbols](#2D-Marker-Symbols)
37+
- [3D Marker Symbols](#3D-Marker-Symbols)
38+
39+
## Basics
40+
41+
You can control marker size, color, symbol, and other aesthetics by styling the `Marker` object associated with a chart.
42+
43+
This can be done by either setting the `Marker` argument of the chart constructor:
44+
*)
45+
46+
open Plotly.NET
47+
open Plotly.NET.TraceObjects
48+
49+
let byConstructor =
50+
Chart.Point(
51+
xy = [1,2],
52+
Marker = Marker.init(
53+
Color=Color.fromKeyword Red,
54+
Size=20
55+
)
56+
)
57+
58+
(*** condition: ipynb ***)
59+
#if IPYNB
60+
byConstructor
61+
#endif // IPYNB
62+
63+
(***hide***)
64+
byConstructor |> GenericChart.toChartHTML
65+
(***include-it-raw***)
66+
67+
(**
68+
or after chart creation with `withMarkerStyle`:
69+
*)
70+
71+
let byStyle =
72+
Chart.Point(xy=[1,2])
73+
|> Chart.withMarkerStyle(
74+
Color=Color.fromKeyword Blue,
75+
Size=50
76+
)
77+
78+
(*** condition: ipynb ***)
79+
#if IPYNB
80+
byStyle
81+
#endif // IPYNB
82+
83+
(***hide***)
84+
byStyle |> GenericChart.toChartHTML
85+
(***include-it-raw***)
86+
87+
(**
88+
## Marker Symbols
89+
90+
Marker symbols control the appearance of points in a plot. There are some things to keep in mind when working with marker symbols:
91+
- 2D and 3D Markers are different types ()
92+
- 2D Markers can be modified using modification syntax
93+
- 3D Markers cannot be modified
94+
95+
### 2D Marker Symbols
96+
97+
2D Marker symbols are set using `StyleParam.MarkerSymbol`.
98+
*)
99+
100+
let cross2D =
101+
Chart.Point(xy=[1,2])
102+
|> Chart.withMarkerStyle(
103+
Color=Color.fromKeyword Blue,
104+
Size=50,
105+
Symbol=StyleParam.MarkerSymbol.Cross
106+
)
107+
108+
(*** condition: ipynb ***)
109+
#if IPYNB
110+
cross2D
111+
#endif // IPYNB
112+
113+
(***hide***)
114+
cross2D |> GenericChart.toChartHTML
115+
(***include-it-raw***)
116+
117+
(**
118+
To modify a symbol, use `StyleParam.MarkerSymbol.Modified`, which takes a MarkerSymbol and a SymbolStyle.
119+
120+
The following code modifies `StyleParam.MarkerSymbol.Circle` with `StyleParam.SymbolStyle.Open` to create an open circle symbol:
121+
*)
122+
123+
let circle2DOpen =
124+
Chart.Point(xy=[1,2])
125+
|> Chart.withMarkerStyle(
126+
Color=Color.fromKeyword Blue,
127+
Size=50,
128+
Symbol=StyleParam.MarkerSymbol.Modified(
129+
StyleParam.MarkerSymbol.Circle,
130+
StyleParam.SymbolStyle.Open
131+
)
132+
)
133+
134+
(*** condition: ipynb ***)
135+
#if IPYNB
136+
circle2DOpen
137+
#endif // IPYNB
138+
139+
(***hide***)
140+
circle2DOpen |> GenericChart.toChartHTML
141+
(***include-it-raw***)
142+
143+
(**
144+
### 3D Marker Symbols
145+
146+
2D Marker symbols are set using `StyleParam.MarkerSymbol3D`.
147+
148+
Keep in mind that these must also be set on the `Symbol3D` property of the `Marker` object, not the `Symbol` property.
149+
*)
150+
151+
let cross3D =
152+
Chart.Point3D(xyz=[1,2,3])
153+
|> Chart.withMarkerStyle(
154+
Color=Color.fromKeyword Blue,
155+
Size=50,
156+
Symbol3D=StyleParam.MarkerSymbol3D.Cross
157+
)
158+
159+
(*** condition: ipynb ***)
160+
#if IPYNB
161+
cross3D
162+
#endif // IPYNB
163+
164+
(***hide***)
165+
cross3D |> GenericChart.toChartHTML
166+
(***include-it-raw***)

0 commit comments

Comments
 (0)