Skip to content

Commit a3b64e1

Browse files
authoredMar 6, 2025··
Merge pull request #482 from plotly/update-docs-#481
update annotation docu
2 parents 6de319f + 87054ed commit a3b64e1

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed
 

Diff for: ‎docs/chart-layout/annotations.fsx

+98
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,101 @@ annotations
7171
(***hide***)
7272
annotations |> GenericChart.toChartHTML
7373
(***include-it-raw***)
74+
75+
76+
(**
77+
## Annotations with logged axes
78+
79+
When using log axes, the values for `X` or `Y` given in `Annotation.init` must be transformed as well even if the axis shows the expected value range.
80+
*)
81+
82+
let y_highrange = [ 2.; 15_000.; 1_600.; 1.5; 3.; 25_000; 25_000.; 15_000; 350; 1. ]
83+
84+
// The default log axis is base 10
85+
let a_log = Annotation.init (X = 5., Y = log10 2_500., Text = "I'm at position<br>x=5, y=2500")
86+
87+
let annotations_log =
88+
Chart.Line(x = x, y = y_highrange, Name = "log_line")
89+
|> Chart.withYAxis(LinearAxis.init(AxisType = StyleParam.AxisType.Log))
90+
|> Chart.withAnnotation a_log
91+
92+
(*** condition: ipynb ***)
93+
#if IPYNB
94+
annotations_log
95+
#endif // IPYNB
96+
97+
(***hide***)
98+
annotations_log |> GenericChart.toChartHTML
99+
(***include-it-raw***)
100+
101+
102+
103+
(**
104+
## Multicharts
105+
106+
Annotations can also be placed using coordinates proportional to the chart canvas, by setting the `XRef` and `YRef` to `"paper"`.
107+
In multi-chart layouts, the reference can be set to the respective x, and y axis-component (e.g. `XRef = x3, YRef = y3` for the third chart within the chart grid).
108+
*)
109+
110+
// setting no reference, the annotation will be placed at the given x and y values in the first chart
111+
let a_multichart1 = Annotation.init (X = 8, Y = 5.0, Text = "no ref defined")
112+
113+
// setting the reference to specific x and y components, the annotation will be placed at the given x and y values in the chart defined by the ref-coordinates
114+
let a_multichart2 = Annotation.init (X = 7, Y = 3.5, XRef = "x1", YRef = "y1", Text = "ref: x1 and y1")
115+
let a_multichart3 = Annotation.init (X = 7, Y = 3.5, XRef = "x2", YRef = "y2", Text = "ref: x2 and y2")
116+
let a_multichart4 = Annotation.init (X = 7, Y = 3.5, XRef = "x3", YRef = "y3", Text = "ref: x3 and y3")
117+
let a_multichart5 = Annotation.init (X = 7, Y = 3.5, XRef = "x4", YRef = "y4", Text = "ref: x4 and y4")
118+
119+
// setting the x and y reference to "paper", the annotation will be placed proportional to the chart canvas
120+
let a_multichart6 = Annotation.init (X = 1.1, Y = 1.1, XRef = "paper", YRef = "paper", Text = "ref: paper@1.1")
121+
let a_multichart7 = Annotation.init (X = 0.5, Y = 0.4, XRef = "paper", YRef = "paper", Text = "ref: paper@0.5")
122+
123+
124+
let annotations_multi =
125+
[
126+
Chart.Line(x = x, y = y, Name = "chart 1")
127+
Chart.Line(x = x, y = y, Name = "chart 2")
128+
Chart.Line(x = x, y = y, Name = "chart 3")
129+
Chart.Line(x = x, y = y, Name = "chart 4")
130+
]
131+
|> Chart.Grid(2, 2)
132+
|> Chart.withAnnotations ([a_multichart1; a_multichart2; a_multichart3; a_multichart4; a_multichart5; a_multichart6; a_multichart7])
133+
134+
(*** condition: ipynb ***)
135+
#if IPYNB
136+
annotations_multi
137+
#endif // IPYNB
138+
139+
(***hide***)
140+
annotations_multi |> GenericChart.toChartHTML
141+
(***include-it-raw***)
142+
143+
(**
144+
In multi-chart layouts *with coupled axis*, the reference can be set to the respective coupled x, and y axis-component (e.g. `XRef = x1, YRef = y2` for the leftmost chart in the second row).
145+
*)
146+
147+
// setting the reference to specific x and y components with coupled axes, the annotation will be placed at the given x and y values in the chart defined by the ref-coordinates
148+
let a_multichart_coupled_1 = Annotation.init (X = 7, Y = 3.5, XRef = "x1", YRef = "y1", Text = "ref: x1 and y1")
149+
let a_multichart_coupled_2 = Annotation.init (X = 7, Y = 3.5, XRef = "x2", YRef = "y1", Text = "ref: x2 and y1")
150+
let a_multichart_coupled_3 = Annotation.init (X = 7, Y = 3.5, XRef = "x2", YRef = "y2", Text = "ref: x2 and y2")
151+
let a_multichart_coupled_4 = Annotation.init (X = 7, Y = 3.5, XRef = "x1", YRef = "y2", Text = "ref: x1 and y2")
152+
153+
154+
let annotations_paper_coupled =
155+
[
156+
Chart.Line(x = x, y = y, Name = "chart 1")
157+
Chart.Line(x = x, y = y, Name = "chart 2")
158+
Chart.Line(x = x, y = y, Name = "chart 3")
159+
Chart.Line(x = x, y = y, Name = "chart 4")
160+
]
161+
|> Chart.Grid(2, 2, Pattern = StyleParam.LayoutGridPattern.Coupled)
162+
|> Chart.withAnnotations ([a_multichart_coupled_1; a_multichart_coupled_2; a_multichart_coupled_3; a_multichart_coupled_4])
163+
164+
(*** condition: ipynb ***)
165+
#if IPYNB
166+
annotations_paper_coupled
167+
#endif // IPYNB
168+
169+
(***hide***)
170+
annotations_paper_coupled |> GenericChart.toChartHTML
171+
(***include-it-raw***)

0 commit comments

Comments
 (0)
Please sign in to comment.