geopandas .p​​lotting()不使用matplotlib.pyplot:isintance()arg2必须是类型的类型或元组

发布于 2025-02-10 19:55:10 字数 1844 浏览 1 评论 0原文

使用matplotlib === 3.5.1&& geopandas === 0.9.0

运行以下命令时:

pos = Figure(figsize=PAGE_DIMS,tight_layout=LAYOUT_DICT)

pos.suptitle("Pos", x=1, y=4, color='g')

b_pos = pos.add_gridspec(3, 9)

ax = pos.add_subplot(b_pos[0, 1:4])

world = geopandas.read_file(geopandas.datasets.get_path('file_name'))

world.plot(ax=ax, color='lightblue', edgecolor='black')

我遇到以下错误,

File "~/python3.8/dist-packages/geopandas/plotting.py", line 925, in __call__
    return plot_dataframe(data, *args, **kwargs)
File "~/python3.8/dist-packages/geopandas/plotting.py", line 689, in plot_dataframe
    return plot_series(
File "~/python3.8/dist-packages/geopandas/plotting.py", line 467, in plot_series
    plt.draw()
File "~/python3.8/dist-packages/matplotlib/pyplot.py", line 952, in draw
    gcf().canvas.draw_idle()
File "~/python3.8/dist-packages/matplotlib/pyplot.py", line 846, in gcf
    return figure()
File "~/python3.8/dist-packages/matplotlib/pyplot.py", line 751, in figure
    if isinstance(num, Figure):
Type: <class 'TypeError'>, Obj: isinstance() arg 2 must be a type or tuple of types, TB: <traceback object at XXXXXXXXX>

我尝试将库降级为无用。也不确定是否有Arg/Kwarg我可以通过以解决此问题。

编辑:我已经确切地发现了例外的位置:在matplotlib.pyplot.figure中,该功能在matplotlib/pyplot.py中的第665行上看起来像:

def figure(num=None,figsize=None,dpi=None,facecolor=None, edgecolor=None, frameon=True, FigureClass=Figure, clear=False,**kwargs):

    if isinstance(num, Figure):
        if num.canvas.manager is None:
            raise ValueError("The passed figure is not managed by pyplot")
        _pylab_helpers.Gcf.set_active(num.canvas.manager)
        return num

当我评论此块时,我将获得所需的输出。也许我错过了尤其?

using matplotlib===3.5.1 && geopandas===0.9.0

When running the following command:

pos = Figure(figsize=PAGE_DIMS,tight_layout=LAYOUT_DICT)

pos.suptitle("Pos", x=1, y=4, color='g')

b_pos = pos.add_gridspec(3, 9)

ax = pos.add_subplot(b_pos[0, 1:4])

world = geopandas.read_file(geopandas.datasets.get_path('file_name'))

world.plot(ax=ax, color='lightblue', edgecolor='black')

I am getting the below error

File "~/python3.8/dist-packages/geopandas/plotting.py", line 925, in __call__
    return plot_dataframe(data, *args, **kwargs)
File "~/python3.8/dist-packages/geopandas/plotting.py", line 689, in plot_dataframe
    return plot_series(
File "~/python3.8/dist-packages/geopandas/plotting.py", line 467, in plot_series
    plt.draw()
File "~/python3.8/dist-packages/matplotlib/pyplot.py", line 952, in draw
    gcf().canvas.draw_idle()
File "~/python3.8/dist-packages/matplotlib/pyplot.py", line 846, in gcf
    return figure()
File "~/python3.8/dist-packages/matplotlib/pyplot.py", line 751, in figure
    if isinstance(num, Figure):
Type: <class 'TypeError'>, Obj: isinstance() arg 2 must be a type or tuple of types, TB: <traceback object at XXXXXXXXX>

I tried downgrading libraries to no avail. Also not sure if there is an arg/kwarg I can pass to get around this issue.

Edit: I have discovered exactly where the exception is getting tripped: in matplotlib.pyplot.figure, the function appears as so, on line 665 in matplotlib/pyplot.py :

def figure(num=None,figsize=None,dpi=None,facecolor=None, edgecolor=None, frameon=True, FigureClass=Figure, clear=False,**kwargs):

    if isinstance(num, Figure):
        if num.canvas.manager is None:
            raise ValueError("The passed figure is not managed by pyplot")
        _pylab_helpers.Gcf.set_active(num.canvas.manager)
        return num

When I comment this block out, I am getting my desired output. Perhaps I'm missing a kwarg?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文