Skip to content

mplexporter not getting Collection offset position due to matplotlib API changes in v3.5 #3624

Closed
@cylammarco

Description

@cylammarco

Using plotly 5.6.0 and matplotlib 3.5.1

https://matplotlib.org/devdocs/api/prev_api_changes/api_changes_3.5.0.html#classes-methods-and-attributes

Collection.set_offset_position and Collection.get_offset_position have been removed; the offset_position of the Collection class is now "screen"

Example code to reproduce the problem:

import numpy as np
from matplotlib import pyplot as plt
from plotly import tools

x = np.arange(10)
y = x **2.

fig1 = plt.figure(1)
plt.vlines(x, 0, max(y))

tools.mpl_to_plotly(fig1)

gives

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\------\AppData\Local\Programs\Python\Python310\lib\site-packages\plotly\tools.py", line 112, in mpl_to_plotly
    matplotlylib.Exporter(renderer).run(fig)
  File "C:\Users\------\AppData\Local\Programs\Python\Python310\lib\site-packages\plotly\matplotlylib\mplexporter\exporter.py", line 53, in run
    self.crawl_fig(fig)
  File "C:\Users\------\AppData\Local\Programs\Python\Python310\lib\site-packages\plotly\matplotlylib\mplexporter\exporter.py", line 124, in crawl_fig
    self.crawl_ax(ax)
  File "C:\Users\------\AppData\Local\Programs\Python\Python310\lib\site-packages\plotly\matplotlylib\mplexporter\exporter.py", line 146, in crawl_ax
    self.draw_collection(ax, collection)
  File "C:\Users\------\AppData\Local\Programs\Python\Python310\lib\site-packages\plotly\matplotlylib\mplexporter\exporter.py", line 289, in draw_collection
    offset_order = offset_dict[collection.get_offset_position()]
AttributeError: 'LineCollection' object has no attribute 'get_offset_position'. Did you mean: '_offset_position'?

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