Skip to content

Commit ce7be77

Browse files
committed
add ticklabelstandoff, ticklabelshift and ticklabelindex
1 parent 51256f2 commit ce7be77

File tree

1 file changed

+58
-2
lines changed

1 file changed

+58
-2
lines changed

doc/python/axes.md

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.3'
9-
jupytext_version: 1.16.1
9+
jupytext_version: 1.16.3
1010
kernelspec:
1111
display_name: Python 3 (ipykernel)
1212
language: python
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.10.11
23+
version: 3.10.14
2424
plotly:
2525
description: How to adjust axes properties in Python - axes titles, styling and
2626
coloring axes and grid lines, ticks, tick labels and more.
@@ -448,6 +448,62 @@ fig.update_yaxes(minor_ticks="inside")
448448
fig.show()
449449
```
450450

451+
#### Adjust Tick Label Positions
452+
453+
*New in 5.23*
454+
455+
You can adjust tick label positions by moving them a number of pixels away from the axis using `ticklabelstandoff` or along the axis using `ticklabelshift`.
456+
457+
In this example, `ticklabelshift=25` shifts the labels 25 pixels to the right along the x-axis. By providing a negative value, we could move the labels 25 pixels to the left, (`ticklabelshift=-25`).
458+
459+
Here, `ticklabelstandoff=15` moves the labels further 15 pixels away from the x-axis. A negative value here would move them close to the axis.
460+
461+
```python
462+
import plotly.express as px
463+
464+
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
465+
466+
fig = px.line(df, x='Date', y='AAPL.High')
467+
468+
fig.update_layout(
469+
xaxis=dict(
470+
ticks='outside',
471+
ticklen=10,
472+
ticklabelshift=25,
473+
ticklabelstandoff=15
474+
)
475+
)
476+
477+
fig.show()
478+
```
479+
480+
#### Use Minor Tick for Label
481+
482+
*New in 5.23*
483+
484+
On date or linear axes, use `ticklabelindex` to use..
485+
486+
To draw the label for the minor tick before each major tick, choose `ticklabelindex` -1, like in the following example.
487+
488+
```python
489+
import plotly.express as px
490+
491+
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
492+
493+
fig = px.line(df, x='Date', y='AAPL.High')
494+
495+
fig.update_layout(
496+
xaxis=dict(
497+
minor=dict(ticks='outside'),
498+
ticks='outside',
499+
ticklen=10,
500+
ticklabelindex=-1
501+
)
502+
)
503+
504+
fig.show()
505+
```
506+
451507
### Axis lines: grid and zerolines
452508

453509
##### Toggling Axis grid lines

0 commit comments

Comments
 (0)