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

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tssweeney opened this issue Nov 18, 2020 · 5 comments
Closed

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

tssweeney opened this issue Nov 18, 2020 · 5 comments

Comments

@tssweeney
Copy link

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

@nicolaskruchten
Copy link
Contributor

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!

@tssweeney
Copy link
Author

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

@carlinmack
Copy link

carlinmack commented Nov 19, 2020

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!)

OnnoEbbens added a commit to MAMBA-python/course-material that referenced this issue Dec 2, 2020
OnnoEbbens added a commit to MAMBA-python/course-material that referenced this issue Dec 3, 2020
* update notebooks

* remove metadata from cells during tests

* update content and contextily installation

* add descartes

* typo

* update installation manual

* update gitignore

* move groundwater model directory

* update gitignore

* restructure and update practical examples

* last update for now

* add cbs_data analyse

* update twitter analysis

* reinstate some files to be ignored

* remove error in camel_bananas function

* update camel problem

* modify text

* remove notebook metadata as well (and not only cell metadata)

* minor changes

* remove all metadata from notebooks

* add on-topic to test

* update travis requirements

* fix travis test errors

* add pyproj to travis req

* add proj to travis req

* add proj4 to travis req

* remove proj from req

* another attempt to let travis install cartopy

* another attempt to let travis install cartopy

* another attempt to let travis install cartopy

* another attempt to let travis install cartopy

* another attempt to let travis install cartopy

* another attempt to let travis install cartopy

* another attempt to let travis install cartopy

* another attempt to let travis install cartopy

* another attempt to let travis install cartopy

* another attempt to let travis install cartopy

* another day another attempt:

* another day another attempt:

* another day another attempt:

* another day another attempt:

* add dependencies

* add dependency

* remove first folium notebook from tests because mplleaflet is not maintained anymore, see this issue plotly/plotly.py#2913
@kr-hansen
Copy link

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.

@gvwilson
Copy link
Contributor

Hi - we are trying to tidy up the stale issues and PRs in Plotly's public repositories so that we can focus on things that are still important to our community. Since this one has been sitting for several years, I'm going to close it; if it is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. Thanks for your help - @gvwilson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants