Skip to content

Add JS example of Annotations with Log Axes #281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
name: Annotations with Log Axes
language: plotly_js
suite: annotations
order: 3.5
sitemap: false
arrangement: horizontal
markdown_content: |
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.
---
var dates = [
"2024-01-01",
"2024-01-02",
"2024-01-03",
"2024-01-04",
"2024-01-05",
"2024-01-06",
];

var y_values = [1, 30, 70, 100, 1000, 10000000];

var trace1 = {
x: dates,
y: y_values,
mode: 'lines+markers',
type: 'scatter'
};

var layout = {
yaxis: {
type: 'log',
},
annotations: [
{
x: '2024-01-05',
y: Math.log10(1000),
text: 'Log axis annotation',
showarrow: true,
xanchor: 'right',
}
]
};

var data = [trace1];

Plotly.newPlot('myDiv', data, layout);