Thanks to visit codestin.com
Credit goes to github.com

Skip to content

'XAxis' object has no attribute '_gridOnMajor' #2913

Closed
@tssweeney

Description

@tssweeney

Hello, matplotlib recently merged a change that removed provide variables from Axis: matplotlib/matplotlib#18769. There are at least 2 places in plotly code that reference these variables:

if axis._gridOnMajor and len(gridlines) > 0:
,
return bool(ax and ax.xaxis._gridOnMajor and ax.yaxis.get_gridlines())
, and
return bool(ax and ax.yaxis._gridOnMajor and ax.yaxis.get_gridlines())

In particular I hit this bug when converting matplotlib to pyplot.

  • matplotlib>=3.3.3
  • plotly>=4.12.0

Repro:

import plotly
import matplotlib.pyplot as plt

fig = plt.figure(1)
ax = plt.plot([1,2,3])
plotly.tools.mpl_to_plotly(fig)

results in

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-c2ca21d8fe91> in <module>()
      1 fig = plt.figure(1)
      2 ax = plt.plot([1,2,3])
----> 3 plotly.tools.mpl_to_plotly(fig)

6 frames
/usr/local/lib/python3.6/dist-packages/plotly/matplotlylib/mplexporter/utils.py in get_grid_style(axis)
    244 def get_grid_style(axis):
    245     gridlines = axis.get_gridlines()
--> 246     if axis._gridOnMajor and len(gridlines) > 0:
    247         color = export_color(gridlines[0].get_color())
    248         alpha = gridlines[0].get_alpha()

AttributeError: 'XAxis' object has no attribute '_gridOnMajor'

FWIW, i think the fix is to replace these calls with _major_tick_kw['gridOn'].

Thank you,
Tim

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions