Skip to content

Commit 13681af

Browse files
committed
add autotickangles example
1 parent 07e2837 commit 13681af

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

Diff for: doc/python/axes.md

+19-2
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.15.1
9+
jupytext_version: 1.16.1
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.4
23+
version: 3.10.11
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.
@@ -363,6 +363,23 @@ fig.update_xaxes(tickangle=45, tickfont=dict(family='Rockwell', color='crimson',
363363
fig.show()
364364
```
365365

366+
##### Auto Tick Angle Options
367+
368+
*New in 5.18*
369+
370+
If `tickangle` is not explicitly set, its default value is `auto`, meaning if the label needs to be rotated to avoid labels overlapping, it will rotate by either 30 or 90 degrees. Using `autotickangles`, you can also specify a list of angles for `tickangle` to use. If `tickangle` is `auto` and you provide a list of angles to `autotickangles`, the label angle will be set to the first value in the list that prevents overlap.
371+
372+
```python
373+
import plotly.express as px
374+
df = px.data.gapminder()
375+
df = df.loc[(df.continent=="Asia") & (df.year==1992)]
376+
fig = px.histogram(df, x=df.country, y=df.gdpPercap)
377+
378+
fig.update_xaxes(autotickangles=[45, 60, 90])
379+
380+
fig.show()
381+
```
382+
366383
#### Enumerated Ticks with Tickvals and Ticktext
367384

368385
The `tickvals` and `ticktext` axis properties can be used together to display custom tick label text at custom locations along an axis. They should be set to lists of the same length where the `tickvals` list contains positions along the axis, and `ticktext` contains the strings that should be displayed at the corresponding positions.

0 commit comments

Comments
 (0)