Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2.8k
Fix add_vline and add_hline with datetime axes#5508
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
Changes from all commits
9bed9d32cf036cb83c5ad82e575905ac0188c18945File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -427,3 +427,79 @@ def test_all_annotation_positions(): | ||
| if __name__ == "__main__": | ||
| draw_all_annotation_positions() | ||
| # Tests for datetime axis annotation support (issue #3065) | ||
| import datetime | ||
| def test_vline_datetime_string_annotation(): | ||
| """add_vline with annotation_text on datetime x-axis should not crash.""" | ||
| fig = go.Figure() | ||
| fig.add_trace(go.Scatter(x=["2018-01-01", "2018-06-01", "2018-12-31"], y=[1, 2, 3])) | ||
| fig.add_vline(x="2018-09-24", annotation_text="test") | ||
| assert len(fig.layout.annotations) == 1 | ||
| assert fig.layout.annotations[0].text == "test" | ||
| assert fig.layout.annotations[0].x == "2018-09-24" | ||
| def test_hline_with_datetime_xaxis(): | ||
| """numeric add_hline should still work with datetime x-axis.""" | ||
| fig = go.Figure() | ||
| fig.add_trace(go.Scatter(x=["2018-01-01", "2018-06-01", "2018-12-31"], y=[1, 2, 3])) | ||
| fig.add_hline(y=2, annotation_text="hline test") | ||
| assert len(fig.layout.annotations) == 1 | ||
| assert fig.layout.annotations[0].text == "hline test" | ||
emilykl marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| assert fig.layout.annotations[0].y == 2 | ||
| def test_vrect_datetime_string_annotation(): | ||
| """add_vrect with annotation_text on datetime x-axis should not crash.""" | ||
| fig = go.Figure() | ||
| fig.add_trace(go.Scatter(x=["2018-01-01", "2018-06-01", "2018-12-31"], y=[1, 2, 3])) | ||
| fig.add_vrect(x0="2018-03-01", x1="2018-09-01", annotation_text="rect test") | ||
| assert len(fig.layout.annotations) == 1 | ||
| assert fig.layout.annotations[0].text == "rect test" | ||
emilykl marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| assert fig.layout.annotations[0].x == "2018-09-01" | ||
| def test_vline_datetime_object_annotation(): | ||
| """add_vline with datetime.datetime object should not crash.""" | ||
| fig = go.Figure() | ||
| fig.add_trace( | ||
| go.Scatter( | ||
| x=[ | ||
| datetime.datetime(2018, 1, 1), | ||
| datetime.datetime(2018, 6, 1), | ||
| datetime.datetime(2018, 12, 31), | ||
| ], | ||
| y=[1, 2, 3], | ||
| ) | ||
| ) | ||
| fig.add_vline(x=datetime.datetime(2018, 9, 24), annotation_text="dt test") | ||
| assert len(fig.layout.annotations) == 1 | ||
| assert fig.layout.annotations[0].text == "dt test" | ||
emilykl marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| assert fig.layout.annotations[0].x == datetime.datetime(2018, 9, 24, 0, 0) | ||
| def test_vrect_datetime_object_annotation(): | ||
| """add_vrect with datetime.datetime objects should compute correct mean.""" | ||
| fig = go.Figure() | ||
| fig.add_trace( | ||
| go.Scatter( | ||
| x=[ | ||
| datetime.datetime(2018, 1, 1), | ||
| datetime.datetime(2018, 6, 1), | ||
| datetime.datetime(2018, 12, 31), | ||
| ], | ||
| y=[1, 2, 3], | ||
| ) | ||
| ) | ||
| fig.add_vrect( | ||
| x0=datetime.datetime(2018, 3, 1), | ||
| x1=datetime.datetime(2018, 9, 1), | ||
| annotation_text="rect dt test", | ||
| ) | ||
| assert len(fig.layout.annotations) == 1 | ||
| assert fig.layout.annotations[0].text == "rect dt test" | ||
emilykl marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| assert fig.layout.annotations[0].x == datetime.datetime(2018, 9, 1) | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.