mplexporter not getting Collection offset position due to matplotlib API changes in v3.5
See original GitHub issueUsing plotly 5.6.0 and matplotlib 3.5.1
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'?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:8
Top Results From Across the Web
API Changes for 3.5.0 — Matplotlib 3.6.2 documentation
The change only affects the interaction between the color, edgecolor, facecolor, and (for Collection s) alpha properties: the color property now needs to...
Read more >What's new in Matplotlib 3.5.0 (Nov 15, 2021)
Setting collection offset transform after initialization. Colors and colormaps. Colormap registry (experimental). Image interpolation now possible at RGBA ...
Read more >matplotlib.collections — Matplotlib 3.6.2 documentation
The extent can change due to any changes in the transform stack, such as changing ... n, 3) array and two offsets from...
Read more >API Changes — Matplotlib 1.5.3 documentation
Previously, they raised a ValueError . This is consistent with all the Date Locators. 'OffsetBox.DrawingArea' respects the 'clip' keyword argument¶. The call ...
Read more >matplotlib.offsetbox — Matplotlib 3.6.2 documentation
The extent can change due to any changes in the transform stack, such as changing ... n, 3) array and two offsets from...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m not using Plotly directly but mplleaflet and I got the same error. I managed to make it work by replacing in this exporter.py file
offset_order = offset_dict[collection.get_offset_position()]
byoffset_order = offset_dict[collection._offset_position]
Hope it helps someone!
we finally moved away from this. as an alternative, converting
matplotlib
figures to image is used in places where interactions (zoom in/out etc.) are not critical.