Plotly.py: 'XAxis' object has no attribute '_gridOnMajor'

Created on 18 Nov 2020  路  4Comments  路  Source: plotly/plotly.py

Hello, matplotlib recently merged a change that removed provide variables from Axis: https://github.com/matplotlib/matplotlib/pull/18769. There are at least 2 places in plotly code that reference these variables: https://github.com/plotly/plotly.py/blob/65625d49226632abcf932d530aa9c90ba1bc59c1/packages/python/plotly/plotly/matplotlylib/mplexporter/utils.py#L246, https://github.com/plotly/plotly.py/blob/65625d49226632abcf932d530aa9c90ba1bc59c1/packages/python/plotly/plotly/matplotlylib/mplexporter/renderers/base.py#L21, and https://github.com/plotly/plotly.py/blob/65625d49226632abcf932d530aa9c90ba1bc59c1/packages/python/plotly/plotly/matplotlylib/mplexporter/renderers/base.py#L25

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

Most helpful comment

Any update on this? Looks like it may have been added, but doesn't look like a pull request was accepted yet? Did somebody do this yet?

If not I'm happy to go to the locations highlighted by @tssweeney and put the line that @carlinmack suggested to submit a pull request.

All 4 comments

Thanks for the detailed bug report! We're not really actively maintaining the matplotlib to Plotly system any more to be honest, so this kind of "rot" is a bit to be expected. We would probably accept a pull request if it's backwards-compatible though!

Thanks @nicolaskruchten for getting back to me. Also @carlinmack for submitting a quick fix. I would appreciate the merge if/when tests pass! (:

oh sorry that's in a different repository that has the same issue! It's a really simple fix though (axis._gridOnMajor -> axis._major_tick_kw['gridOn']) and the lines are listed above. I could fix it, but I don't have reference code to test with (I've never used plotly!)

Any update on this? Looks like it may have been added, but doesn't look like a pull request was accepted yet? Did somebody do this yet?

If not I'm happy to go to the locations highlighted by @tssweeney and put the line that @carlinmack suggested to submit a pull request.

Was this page helpful?
0 / 5 - 0 ratings