๐Ÿ“ฃ Announcing Plotly.py 5.8.0 - Better Autocompletions with Type Hints, Minor Ticks

Update: new post on version 5.13.0 was released since this was posted.

Iโ€™m happy to announce that Plotly.py 5.8.0 is now available for download via pip and conda! For up-to-date installation and upgrading instructions please see our Getting Started documentation page and if you run into trouble, check out our Troubleshooting Guide.

Whatโ€™s new in Plotly.py 5.8

Our changelog has links to individual pull requests, but here are the highlights:

:label: Better Autocompletions with Type Hints

Thanks to a community pull request, our lazy imports no longer interfere with type checkers and we can now add type hints throughout plotly.graph_objects and we started by type-hinting all the methods which return Figure objects so your editor can give you nice autocompletion hints as you code, even as you chain methods together:

gif

Weโ€™ve also added type hints to Plotly Express, so you can type fig = px.bar(...) and then get completions from typing fig.<tab> in your favourite editor.

Most editors should be able to use these hints to give you nice autocompletion, including Jupyter Notebook and Lab (where they work best if you use a language server, for example with jupyterlab-lsp) or in VSCode or PyCharm.

:straight_ruler: Minor Ticks

Cartesian axes now support minor ticks and gridlines:

import plotly.express as px

df = px.data.tips()
fig = px.scatter(df, x="total_bill", y="tip", color="sex")

fig.update_xaxes(minor_ticks="outside", minor_showgrid=True)
fig.update_yaxes(minor_ticks="outside", minor_showgrid=True)

This lets you do some interesting things, for example having major ticks/grids on month boundaries and minor ones on week boundaries (the example below also shows off our new griddash parameter for dashed gridlines) and this looks really great with the tick labels set to period mode so that the month labels below are centered on the month they denote:

import pandas as pd
import plotly.express as px

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
df = df.loc[(df["Date"] >= "2016-07-01") & (df["Date"] <= "2016-12-01")]

fig = px.line(df, x='Date', y='AAPL.High')
fig.update_xaxes(ticks= "outside",  ticklabelmode= "period", 
                 tickcolor= "black",  ticklen=10, 
                 minor=dict(ticklen=4,  
                     dtick=7*24*60*60*1000,  
                     tick0="2016-07-03", 
                     griddash='dot', gridcolor='white')
                )

This feature was anonymously sponsored, so thanks to our sponsor :heart:!

:heart: Powered by Plotly.js 2.12.1 and perfect for Dash 2.4

The version of Plotly.js that Plotly.py 5.8.0 is built on is the same one thatโ€™s bundled with the just-released Dash 2.4 so we recommend that if youโ€™re a Dash user you upgrade to Dash 2.4, to get the full benefit of all of these libraries working together.

:package: Get it now!

To sum up: Plotly.py 5.8.0 is out and if youโ€™re excited about any of the above features, head on over to our Getting Started documentation page for full installation instructions!

:reminder_ribbon: In Case You Missed It: Previous Announcements

8 Likes

Question for the community: in addition to posts like these, would folks be interested in me (or someone else!) recording something like 1-2minute video showing these features in action?

7 Likes