Search code examples
pythonmatplotlibplotly

How to solve: 'PathCollection' object has no attribute 'get_offset_position'


I try to test a simple Plotly examaple but I run into this error. My code is just this:

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

mpl_fig, ax = plt.subplots()
ax.scatter(x=[1, 2, 3], y=[23, 12, 34])
plotly_fig = mpl_to_plotly(mpl_fig)
plotly_fig

Can someone help me out here?


Solution

  • See /mpl-to-plotly-limitations. It's really not supported or maintained. I'd recommend going straight to plotly with the data:

    import matplotlib.pyplot as plt
    from plotly.tools import mpl_to_plotly
    import plotly.express as px
    
    # mpl_fig, ax = plt.subplots()
    # ax.scatter(x=[1, 2, 3], y=[23, 12, 34])
    # plotly_fig = mpl_to_plotly(mpl_fig)
    # # plotly_fig
    
    px.scatter(x=[1, 2, 3], y=[23, 12, 34])