Skip to content

Commit a695347

Browse files
authored
Merge pull request #281 from plotly/add-annotations-example
Add JS example of Annotations with Log Axes
2 parents b285dce + 5af3df3 commit a695347

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
name: Annotations with Log Axes
3+
language: plotly_js
4+
suite: annotations
5+
order: 3.5
6+
sitemap: false
7+
arrangement: horizontal
8+
markdown_content: |
9+
If the `x` or `y` positions of an annotation reference a log axis, you need to provide that position as a `log10` value when adding the annotation. In this example, the `yaxis` is a log axis so we pass the `log10` value of `1000` to the annotation's `y` position.
10+
---
11+
var dates = [
12+
"2024-01-01",
13+
"2024-01-02",
14+
"2024-01-03",
15+
"2024-01-04",
16+
"2024-01-05",
17+
"2024-01-06",
18+
];
19+
20+
var y_values = [1, 30, 70, 100, 1000, 10000000];
21+
22+
var trace1 = {
23+
x: dates,
24+
y: y_values,
25+
mode: 'lines+markers',
26+
type: 'scatter'
27+
};
28+
29+
var layout = {
30+
yaxis: {
31+
type: 'log',
32+
},
33+
annotations: [
34+
{
35+
x: '2024-01-05',
36+
y: Math.log10(1000),
37+
text: 'Log axis annotation',
38+
showarrow: true,
39+
xanchor: 'right',
40+
}
41+
]
42+
};
43+
44+
var data = [trace1];
45+
46+
Plotly.newPlot('myDiv', data, layout);

0 commit comments

Comments
 (0)