【发布时间】:2020-09-18 10:18:36
【问题描述】:
而不是以下:
fig, ax = plt.subplots()
x = [1, 2]
y = [4, 5]
ax.scatter(x, y, s=100)
我想要:
def plot(ax, x, y):
ax_c = copy.deepcopy(ax)
ax_c.scatter(x, y, s=100)
return ax_c
fig, ax = plt.subplots()
x = [1, 2]
y = [4, 5]
ax = plot(ax, x, y)
但是,这不起作用,出现以下错误:
NotImplementedError: TransformNode instances can not be copied. Consider using frozen() instead.
所以,我想知道如何编写一个函数,该函数将 matplotlib ax 作为输入,创建它的副本,更改副本并返回它。我想这样做的原因是我可以拥有独立的功能。
编辑
以下不是合适的解决方案:
def plot(ax_c, x, y):
ax_c.scatter(x, y, s=100)
return ax_c
因为这里的 return 语句可以替换为 None 并且它仍然可以正常工作。
【问题讨论】:
-
试试解决方案here
标签: python matplotlib plot data-visualization