Skip to content
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

AttributeError: 'PatchCollection' object has no attribute 'get_offset_position' #83

Open
pbartusch opened this issue Aug 5, 2022 · 3 comments

Comments

@pbartusch
Copy link

Hi,

I am currently reproducing code for plotting maps of Germany (https://juanitorduz.github.io/germany_plots/).

I try to get the interactive map running:

import mplleaflet

fig, ax = plt.subplots()

berlin_df.plot(
    ax=ax,
    alpha=0.2
)

berlin_neighbourhoods_df.plot(
    ax=ax,
    column='neighbourhood_group',
    categorical=True,
    cmap='tab20',
)

mplleaflet.display(fig=fig)

(one of the last steps of the tutorial)

I already fixed the _gridOnMajor bug like suggested here: #80 (thanks to @22tommibaer01).

Unfortunately, I ran into another bug with the following error log:

[...]
File ~/.pyenv/versions/3.10.1/lib/python3.10/site-packages/mplleaflet/mplexporter/exporter.py:263, in Exporter.draw_collection(self, ax, collection, force_pathtrans, force_offsettrans)
    255 styles = {'linewidth': collection.get_linewidths(),
    256           'facecolor': collection.get_facecolors(),
    257           'edgecolor': collection.get_edgecolors(),
    258           'alpha': collection._alpha,
    259           'zorder': collection.get_zorder()}
    261 offset_dict = {"data": "before",
    262                "screen": "after"}
--> 263 offset_order = offset_dict[collection.get_offset_position()]
    265 self.renderer.draw_path_collection(paths=processed_paths,
    266                                    path_coordinates=path_coords,
    267                                    path_transforms=path_transforms,
   (...)
    271                                    styles=styles,
    272                                    mplobj=collection)

AttributeError: 'PatchCollection' object has no attribute 'get_offset_position'

This seems to be related to the plotly issue described here: plotly/plotly.py#3624, but I have no idea how to fix this.

My environment looks like this:

> pip show mplleaflet
Name: mplleaflet
Version: 0.0.5

> pip show matplotlib
Name: matplotlib
Version: 3.5.1

Help is much appreciated. Thanks!

@juanitorduz
Copy link

Hey! I'm the author of the blog 👋 ! Unfortunately, I'm facing the same issue and I have not been able to resolve it. Any tip or hint is highly appreciated 😄 !

@GabrielJunqueira
Copy link

Hey, any update on this? I'm facing the same issue here.

@gilles75-LDG
Copy link

I should preface by saying that I am not software developer, just someone who thought I could use this package in my work. I don't know if this will be helpful to anyone, but I got around this and was able to make a plot by first commenting out the offset_order line in mplexporter/exporter.py, and then in the following line setting the offset_order argument equal to False.

` # offset_order = offset_dict[collection.get_offset_position()]

    self.renderer.draw_path_collection(paths=processed_paths,
                                       path_coordinates=path_coords,
                                       path_transforms=path_transforms,
                                       offsets=offsets,
                                       offset_coordinates=offset_coords,
                                       offset_order=False,
                                       styles=styles,
                                       mplobj=collection)

`
I'm sure this breaks some other functionality (the points I'm scattering no longer maintain the same order as in the matplotlib scatter), but at least I could plot points on a map.

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

4 participants