4

I have a matplotlib figure that I want to convert to plotly

import matplotlib.pyplot as plt
from plotly.tools import mpl_to_plotly

fig = plt.figure()

## Lots of code to create my figure ##

plotly_fig = mpl_to_plotly(fig)

The error I get is AttributeError: 'Spine' object has no attribute 'is_frame_like'

I thought the function was pretty straightforward, how do I fix this?

1 Answers1

3

This error occurs is because it calls a removed function in Matplotlib.

Warning (from warnings module):
  File "C:\Program Files\Python36\lib\site-packages\plotly\matplotlylib\mpltools.py", line 368
    spine_frame_like = spine.is_frame_like()
MatplotlibDeprecationWarning: 
The is_frame_like function was deprecated in Matplotlib 3.1 and will be removed in 3.3.

In the latest commit of plotly packages/python/plotly/plotly/matplotlylib/mpltools.py line 368, it still calls is_frame_like() function. There is already an issue tracking this. You may need choose to downgrade Matplotlib if you still want to use mpl_to_plotly() function.

nicolaskruchten, a member of the Plotly organization, says in that issue

Indeed, our matplotlib conversion utility should be considered deprecated at this point as it isn’t being actively maintained to track deprecations and changes in matplotlib itself so it works best with older versions of matplotlib. I should update the docstrings accordingly.

In the meantime, he claims

That said, if someone wants to work on it to bring it back up to date I’d be happy to work with them to integrate the changes :)

Ynjxsjmh
  • 28,441
  • 6
  • 34
  • 52
  • Looking at the comments in that issue, it looks like Plotly is considering `mpl_to_plotly` to be deprecated. – nedned Aug 10 '20 at 02:30
  • @nedned Thank you, I have added that to my answer in case someone may not look at that issue carefully. – Ynjxsjmh Aug 10 '20 at 04:19