Search code examples
pythonplotlyplotly-dashplotly-python

Plotly Dash | Remove minor ticks


Goal: Run example code and run example with and without minor ticks.

Plotly documentation has example code of a graph with minor ticks. Running the code fails.

import plotly.express as px
import pandas as pd

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


fig.update_xaxes(minor=dict(ticklen=6, tickcolor="black", showgrid=True))
fig.update_yaxes(minor_ticks="inside")

fig.show()

Source - "Adding minor ticks"

Error:

(linechart) daniel@ubuntu-pcs:~/PycharmProjects/linechart$ python linechart/del.py 
Traceback (most recent call last):
  File "/home/daniel/PycharmProjects/linechart/linechart/del.py", line 8, in <module>
    fig.update_xaxes(minor=dict(ticklen=6, tickcolor="black", showgrid=True))
  File "/home/daniel/miniconda3/envs/linechart/lib/python3.9/site-packages/plotly/graph_objs/_figure.py", line 20166, in update_xaxes
    obj.update(patch, overwrite=overwrite, **kwargs)
  File "/home/daniel/miniconda3/envs/linechart/lib/python3.9/site-packages/plotly/basedatatypes.py", line 5082, in update
    BaseFigure._perform_update(self, kwargs, overwrite=overwrite)
  File "/home/daniel/miniconda3/envs/linechart/lib/python3.9/site-packages/plotly/basedatatypes.py", line 3877, in _perform_update
    raise err
ValueError: Invalid property specified for object of type plotly.graph_objs.layout.XAxis: 'minor'

Did you mean "mirror"?
...
Bad property path:
minor
^^^^^

Solution

  • Remove all minor ticks:

    fig.update_xaxes(dtick=1)
    fig.update_yaxes(dtick=1)
    

    However, this doesn't solve the documentation's code snippet.