Skip to content

Commit 728b95e

Browse files
authored
Minor ticks and grid lines docs (#3693)
* Update axes.md - Add minor ticks example - Add griddash example * Minor edit * Update axes.md * Update axes.md * Update axes.md * Update time-series.md * Update time-series.md * Update axes.md * Update axes.md * add log plot example * Update axes.md * Update axes.md * Update axes.md * Update log-plot.md * Update axes.md * Update axes.md * Update time-series.md * Update time-series.md * update to dict( convention * Update axes.md * Update time-series.md
1 parent d08e0c0 commit 728b95e

File tree

3 files changed

+106
-8
lines changed

3 files changed

+106
-8
lines changed

Diff for: doc/python/axes.md

+39
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,30 @@ fig.update_layout(title_text="Apple Stock Price")
380380
fig.show()
381381
```
382382

383+
#### Adding minor ticks
384+
385+
_new in 5.8_
386+
387+
You can position and style minor ticks on a Cartesian axis using `minor`. This takes a `dict` of properties to apply to minor ticks. Available properties include: `tickmode`, `tickvals`, `tickcolor`, `ticklen`, `tickwidth`, `dtick`, `tick0`, `nticks`, `ticks`, `showgrid`, `gridcolor`, `griddash`, and `gridwidth`.
388+
389+
In the following example, we add minor ticks to the x-axis and then to the y-axis. For the y-axis we add ticks on the inside: `ticks="inside"`. On the x-axis we've specified some additional properties to style the minor ticks, setting the length of the ticks with `ticklen` and the color with `tickcolor`. We've also turned on grid lines for the x-axis minor ticks using `showgrid`.
390+
391+
Note: Minor ticks and grid lines are not currently supported on color bars, ternary plots, polar charts, geo plots, or on multi-categorical, or 3D axes.
392+
393+
```python
394+
import plotly.express as px
395+
import pandas as pd
396+
397+
df = px.data.tips()
398+
fig = px.scatter(df, x="total_bill", y="tip", color="sex")
399+
400+
401+
fig.update_xaxes(minor=dict(ticklen=6, tickcolor="black", showgrid=True))
402+
fig.update_yaxes(minor=dict(ticks="inside"))
403+
404+
fig.show()
405+
```
406+
383407
### Axis lines: grid and zerolines
384408

385409
##### Toggling Axis grid lines
@@ -464,6 +488,21 @@ fig.update_yaxes(showgrid=True, gridwidth=1, gridcolor='LightPink')
464488
fig.show()
465489
```
466490

491+
_new in 5.8_
492+
493+
By default grid lines are `solid`. Set the `griddash` property to change this style. In this example we display the x-axis grid lines as `dot`. It can also be set to `dash`, `longdash`, `dashdot`, or `longdashdot`.
494+
495+
```python
496+
import plotly.express as px
497+
df = px.data.iris()
498+
499+
fig = px.scatter(df, x="sepal_width", y="sepal_length", facet_col="species")
500+
fig.update_xaxes(showgrid=True, gridwidth=1, gridcolor='LightPink', griddash='dot')
501+
fig.update_yaxes(showgrid=True, gridwidth=1, gridcolor='LightPink')
502+
503+
fig.show()
504+
```
505+
467506
##### Styling zero lines
468507

469508
The width and color of axis zero lines are controlled by the `zerolinewidth` and `zerolinecolor` axis properties.

Diff for: doc/python/log-plot.md

+24-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ jupyter:
55
text_representation:
66
extension: .md
77
format_name: markdown
8-
format_version: '1.2'
9-
jupytext_version: 1.4.2
8+
format_version: '1.3'
9+
jupytext_version: 1.13.7
1010
kernelspec:
11-
display_name: Python 3
11+
display_name: Python 3 (ipykernel)
1212
language: python
1313
name: python3
1414
language_info:
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.7.7
23+
version: 3.9.0
2424
plotly:
2525
description: How to make Log plots in Python with Plotly.
2626
display_as: scientific
@@ -60,6 +60,26 @@ fig = px.scatter(df, x="gdpPercap", y="lifeExp", hover_name="country",
6060
fig.show()
6161
```
6262

63+
#### Adding minor ticks
64+
65+
_new in 5.8_
66+
67+
You can position and style minor ticks using `minor`. This takes a `dict` of properties to apply to minor ticks. Available properties include: `tickmode`, `tickvals`, `tickcolor`, `ticklen`, `tickwidth`, `dtick`, `tick0`, `nticks`, `ticks`, `showgrid`, `gridcolor`, `griddash`, and `gridwidth`.
68+
69+
In this example we set the tick length with `ticklen`, add the ticks on the inside with `ticks="inside"`, and turn grid lines on with `howgrid=True`.
70+
71+
```python
72+
import plotly.express as px
73+
df = px.data.gapminder().query("year == 2007")
74+
75+
fig = px.scatter(df, x="gdpPercap", y="lifeExp", hover_name="country",
76+
log_x=True, range_x=[1,100000], range_y=[0,100])
77+
78+
fig.update_xaxes(minor=dict(ticks="inside", ticklen=6, showgrid=True))# {"ticks": "inside", "ticklen": 6, "showgrid": True})
79+
80+
fig.show()
81+
```
82+
6383
### Logarithmic Axes with Graph Objects
6484

6585
If Plotly Express does not provide a good starting point, it is also possible to use [the more generic `go.Figure` class from `plotly.graph_objects`](/python/graph-objects/).

Diff for: doc/python/time-series.md

+43-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ jupyter:
55
text_representation:
66
extension: .md
77
format_name: markdown
8-
format_version: '1.2'
9-
jupytext_version: 1.4.2
8+
format_version: '1.3'
9+
jupytext_version: 1.13.7
1010
kernelspec:
11-
display_name: Python 3
11+
display_name: Python 3 (ipykernel)
1212
language: python
1313
name: python3
1414
language_info:
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.7.7
23+
version: 3.9.0
2424
plotly:
2525
description: How to plot date and time in python.
2626
display_as: financial
@@ -135,6 +135,45 @@ fig.update_xaxes(
135135
fig.show()
136136
```
137137

138+
### Adding Minor Ticks
139+
140+
_new in 5.8_
141+
142+
You can add minor ticks to an axis with `minor`. This takes a `dict` of properties to apply to minor ticks. Available properties include: `tickmode`, `tickvals`, `tickcolor`, `ticklen`, `tickwidth`, `dtick`, `tick0`, `nticks`, `ticks`, `showgrid`, `gridcolor`, `griddash`, and `gridwidth`.
143+
144+
In this example, we've added minor ticks to the inside of the x-axis and turned on grid lines.
145+
146+
```python
147+
import pandas as pd
148+
import plotly.express as px
149+
150+
df = px.data.stocks()
151+
fig = px.line(df, x='date', y="GOOG")
152+
153+
fig.update_xaxes(minor=dict(ticks="inside", showgrid=True))
154+
155+
fig.show()
156+
```
157+
158+
#### Monthly Period Labels With Weekly Minor Ticks
159+
160+
_new in 5.8_
161+
162+
You can set `dtick` on `minor` to control the spacing for minor ticks and grid lines. In the following example, by setting `dtick=7*24*3.6e6` (the number of milliseconds in a week) and setting `tick0="2016-07-04"` (the first Monday in our data), a minor tick and grid line is displayed for the start of each week. When zoomed out, we can see where each month and week begins and ends.
163+
164+
```python
165+
import pandas as pd
166+
import plotly.express as px
167+
168+
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
169+
df = df.loc[(df["Date"] >= "2016-07-01") & (df["Date"] <= "2016-12-01")]
170+
171+
fig = px.line(df, x='Date', y='AAPL.High')
172+
fig.update_xaxes(ticks= "outside", ticklabelmode= "period", tickcolor= "black", tickwidth=2, ticklen=10, minor=dict(ticks="outside", dtick=7*24*3.6e6, tick0="2016-07-04", griddash='dot', gridcolor='pink'))
173+
174+
fig.show()
175+
```
176+
138177
### Summarizing Time-series Data with Histograms
139178

140179
Plotly [histograms](/python/histograms/) are powerful data-aggregation tools which even work on date axes. In the figure below, we pass in daily data and display it as monthly averages by setting `histfunc="avg` and `xbins_size="M1"`.

0 commit comments

Comments
 (0)