You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/python/axes.md
+127-126
Original file line number
Diff line number
Diff line change
@@ -81,14 +81,105 @@ fig.show()
81
81
82
82
The different groups of Cartesian axes properties are
83
83
84
+
- title of the axis
84
85
- tick values (locations of tick marks) and tick labels. Tick labels and grid lines are placed at tick values.
85
86
- lines: grid lines (passing through tick values), axis lines, zero lines
86
-
- title of the axis
87
87
- range of the axis
88
88
- domain of the axis
89
89
90
90
The examples on this page apply to axes of any type, but extra attributes are available for [axes of type `category`](/pythone/categorical-axes/) and [axes of type `date`](/python/time-series/).
91
91
92
+
93
+
#### Set and Style Axes Title Labels
94
+
95
+
##### Set axis title text with Plotly Express
96
+
97
+
Axis titles are automatically set to the column names when [using Plotly Express with a data frame as input](/python/px-arguments/).
Axis titles are set using the nested `title.text` property of the x or y axis. Here is an example of creating a new figure and using `update_xaxes` and `update_yaxes`, with magic underscore notation, to set the axis titles.
131
+
132
+
```python
133
+
import plotly.express as px
134
+
135
+
fig = px.line(y=[1, 0])
136
+
137
+
fig.update_xaxes(title_text='Time')
138
+
fig.update_yaxes(title_text='Value A')
139
+
140
+
fig.show()
141
+
```
142
+
143
+
### Set axis title position
144
+
145
+
This example sets `standoff` attribute to cartesian axes to determine the distance between the tick labels and the axis title. Note that the axis title position is always constrained within the margins, so the actual standoff distance is always less than the set or default value. By default [automargin](https://plotly.com/python/setting-graph-size/#automatically-adjust-margins) is `True` in Plotly template for the cartesian axis, so the margins will be pushed to fit the axis title at given standoff distance.
146
+
147
+
```python
148
+
import plotly.graph_objects as go
149
+
150
+
fig = go.Figure(go.Scatter(
151
+
mode="lines+markers",
152
+
y= [4, 1, 3],
153
+
x= ["December", "January", "February"]))
154
+
155
+
fig.update_xaxes(
156
+
tickangle=90,
157
+
title_text="Month",
158
+
title_font= {"size": 20},
159
+
title_standoff=25)
160
+
161
+
fig.update_yaxes(
162
+
title_text="Temperature",
163
+
title_standoff=25)
164
+
165
+
fig.show()
166
+
```
167
+
168
+
##### Set axis title font
169
+
170
+
Here is an example that configures the font family, size, and color for the axis titles in a figure created using Plotly Express.
##### Toggle grid and zerolines with update axis methods
286
-
287
-
Axis properties can be also updated for figures after they are constructed using the `update_xaxes` and `update_yaxes` graph object figure methods.
288
-
289
-
Here is an example that disables the x and y axis grid and zero lines using `update_xaxes` and `update_yaxes`.
290
-
291
-
```python
292
-
import plotly.express as px
293
-
294
-
fig = px.line(y=[1, 0])
295
-
fig.update_xaxes(showgrid=False, zeroline=False)
296
-
fig.update_yaxes(showgrid=False, zeroline=False)
297
-
298
-
fig.show()
299
-
```
300
-
301
-
##### Toggle grid and zerolines for figure created with Plotly Express
302
-
303
-
An advantage of using the `update_xaxis` and `update_yaxis` methods is that these updates will (by default) apply to all axes in the figure. This is especially useful when customizing figures created using Plotly Express, figure factories, or `make_subplots`.
304
-
305
-
Here is an example of disabling all grid and zero lines in a faceted figure created by Plotly Express.
Axis titles are set using the nested `title.text` property of the x or y axis. Here is an example of creating a new figure and using `update_xaxes` and `update_yaxes`, with magic underscore notation, to set the axis titles.
393
-
394
-
```python
395
-
import plotly.express as px
396
-
397
-
fig = px.line(y=[1, 0])
398
-
399
-
fig.update_xaxes(title_text='Time')
400
-
fig.update_yaxes(title_text='Value A')
401
-
402
-
fig.show()
403
-
```
404
-
405
-
### Set axis title position
406
-
407
-
This example sets `standoff` attribute to cartesian axes to determine the distance between the tick labels and the axis title. Note that the axis title position is always constrained within the margins, so the actual standoff distance is always less than the set or default value. By default [automargin](https://plotly.com/python/setting-graph-size/#automatically-adjust-margins) is `True` in Plotly template for the cartesian axis, so the margins will be pushed to fit the axis title at given standoff distance.
408
-
409
-
```python
410
-
import plotly.graph_objects as go
411
-
412
-
fig = go.Figure(go.Scatter(
413
-
mode="lines+markers",
414
-
y= [4, 1, 3],
415
-
x= ["December", "January", "February"]))
416
-
417
-
fig.update_layout(
418
-
xaxis=dict(
419
-
tickangle=90,
420
-
title_text="Month",
421
-
title_font= {"size": 20},
422
-
title_standoff=25),
423
-
yaxis=dict(
424
-
title_text="Temperature",
425
-
title_standoff=25))
426
-
427
-
fig.show()
428
-
```
429
-
430
-
##### Set axis title font
431
-
432
-
Here is an example that configures the font family, size, and color for the axis titles in a figure created using Plotly Express.
Copy file name to clipboardExpand all lines: doc/python/facet-plots.md
+17-3
Original file line number
Diff line number
Diff line change
@@ -107,7 +107,7 @@ fig.show()
107
107
108
108
Since subplot figure titles are [annotations](https://plotly.com/python/text-and-annotations/#simple-annotation), you can use the `for_each_annotation` function to customize them, for example to remove the equal-sign (`=`).
109
109
110
-
In the following example, we pass a lambda function to `for_each_annotation` in order to change the figure subplot titles from `smoker=No` and `smoker=Yes` to just `No` and `Yes`.
110
+
In the following example, we pass a lambda function to `for_each_annotation` in order to change the figure subplot titles from `smoker=No` and `smoker=Yes` to just `No` and `Yes`.
By default, Plotly Express lays out categorical data in the order in which it appears in the underlying data. Every 2-d cartesian Plotly Express function also includes a `category_orders` keyword argument which can be used to control [the order in which categorical axes are drawn](/python/categorical-axes/), but beyond that can also control [the order in which discrete colors appear in the legend](/python/discrete-color/), and the order in which facets are laid out.
The `facet_row_spacing` and `facet_col_spacing` arguments can be used to control the spacing between rows and columns. These values are specified in fractions of the plotting area in paper coordinates and not in pixels, so they will grow or shrink with the `width` and `height` of the figure.
136
+
The `facet_row_spacing` and `facet_col_spacing` arguments can be used to control the spacing between rows and columns. These values are specified in fractions of the plotting area in paper coordinates and not in pixels, so they will grow or shrink with the `width` and `height` of the figure.
123
137
124
138
The defaults work well with 1-4 rows or columns at the default figure size with the default font size, but need to be reduced to around 0.01 for very large figures or figures with many rows or columns. Conversely, if activating tick labels on all facets, the spacing will need to be increased.
125
139
@@ -140,7 +154,7 @@ fig.show()
140
154
141
155
### Synchronizing axes in subplots with `matches`
142
156
143
-
Using `facet_col` from `plotly.express` let [zoom](https://help.plotly.com/zoom-pan-hover-controls/#step-3-zoom-in-and-zoom-out-autoscale-the-plot) and [pan](https://help.plotly.com/zoom-pan-hover-controls/#step-6-pan-along-axes) each facet to the same range implicitly. However, if the subplots are created with `make_subplots`, the axis needs to be updated with `matches` parameter to update all the subplots accordingly.
157
+
Using `facet_col` from `plotly.express` let [zoom](https://help.plotly.com/zoom-pan-hover-controls/#step-3-zoom-in-and-zoom-out-autoscale-the-plot) and [pan](https://help.plotly.com/zoom-pan-hover-controls/#step-6-pan-along-axes) each facet to the same range implicitly. However, if the subplots are created with `make_subplots`, the axis needs to be updated with `matches` parameter to update all the subplots accordingly.
144
158
145
159
Zoom in one trace below, to see the other subplots zoomed to the same x-axis range. To pan all the subplots, click and drag from the center of x-axis to the side:
0 commit comments