Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 55c8075

Browse filesBrowse files
date tick label second line
1 parent 4024629 commit 55c8075
Copy full SHA for 55c8075

File tree

1 file changed

+5
-5
lines changed
Filter options

1 file changed

+5
-5
lines changed

‎doc/python/time-series.md

Copy file name to clipboardExpand all lines: doc/python/time-series.md
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ fig.show()
8787

8888
By default, the tick labels (and optional ticks) are associated with a specific grid-line, and represent an *instant* in time, for example, "00:00 on February 1, 2018". Tick labels can be formatted using the `tickformat` attribute (which accepts the [d3 time-format formatting strings](https://github.com/d3/d3-time-format)) to display only the month and year, but they still represent an instant by default, so in the figure below, the text of the label "Feb 2018" spans part of the month of January and part of the month of February. The `dtick` attribute controls the spacing between gridlines, and the `"M1"` setting means "1 month". This attribute also accepts a number of milliseconds, which can be scaled up to days by multiplying by `24*60*60*1000`.
8989

90+
Date axis tick labels have the special property that any portion after the first instance of `'\n'` in `tickformat` will appear on a second line only once per unique value, as with the year numbers in the example below. To have the year number appear on every tick label, `'<br>'` should be used instead of `'\n'`.
91+
9092
Note that by default, the formatting of values of X and Y values in the hover label matches that of the tick labels of the corresponding axes, so when customizing the tick labels to something broad like "month", it's usually necessary to [customize the hover label](/python/hover-text-and-formatting/) to something narrower like the acutal date, as below.
9193

9294
```python
@@ -97,8 +99,7 @@ fig = px.line(df, x="date", y=df.columns,
9799
title='custom tick labels')
98100
fig.update_xaxes(
99101
dtick="M1",
100-
tickformat="%b %Y",
101-
range=["2018-01-01", "2018-12-31"])
102+
tickformat="%b\n%Y")
102103
fig.show()
103104
```
104105

@@ -116,9 +117,8 @@ fig = px.line(df, x="date", y=df.columns,
116117
title='custom tick labels with ticklabelmode="period"')
117118
fig.update_xaxes(
118119
dtick="M1",
119-
tickformat="%b %Y",
120-
ticklabelmode="period",
121-
range=["2018-01-01", "2018-12-31"])
120+
tickformat="%b\n%Y",
121+
ticklabelmode="period")
122122
fig.show()
123123
```
124124

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.