geopandas .plotting()不使用matplotlib.pyplot:isintance()arg2必须是类型的类型或元组
使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论