不能把单个艺术家放在一个以上的人物中 [英] Can not put single artist in more than one figure

查看:50
本文介绍了不能把单个艺术家放在一个以上的人物中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的问题.

我创建了一个绘制圆形列表的函数.我需要先用圆C2绘制圆C1,然后再用C3 ....绘制C40.

I create a function that plot a list of circles. I need to plot my circle C1 first with a circle C2 then with C3.... until C40.

import matplotlib.pyplot as plt 
from matplotlib.patches import Circle

def plot_circle(Liste_circles):


    fig = plt.figure(figsize=(5,5))   
    ax = fig.add_subplot(111)

    # On définie un fond blanc
    ax.set_facecolor((1, 1, 1))

    ax.set_xlim(-5, 15)
    ax.set_ylim(-6, 12)    

    for c in Liste_circles:
        ax.add_patch(c)

    plt.show()

现在我创建C1:

C1=Circle(xy=(3, 4), radius=2, fill=False, color='g')

最后我尝试绘制它.
第一个情节有效:

An finally I try to plot it.
The first plot worked:

C2=Circle(xy=(6, 3), radius=4, fill=False, color='b')
plot_circle([C1,C2])

第二个失败:

C3=Circle(xy=(7, 2), radius=4, fill=False, color='b')
plot_circle([C1,C3])

出现错误:

运行时错误:不能将单个艺术家放入多个图形中

RuntimeError: Can not put single artist in more than one figure

我可以这样做:

C1=Circle(xy=(3, 4), radius=2, fill=False, color='g')
C3=Circle(xy=(7, 2), radius=4, fill=False, color='b')
plot_circle([C1,C3])

如何将我的圆 C1 与其他 40 个圆一起绘制,而不必每次都重新创建 C1?(我的程序花了10分钟才能通过复杂的算法创建C1,我无法在40个图中的每一个处都重新创建它.).

How can I do to plot my circle C1 with 40 other circles without having to recreate C1 each time? (My program took 10min to create C1 throught a complicated algorithme, I cannot recreate it at each of the 40 plot....).

推荐答案

这里是如何使它工作:只需复制圆圈并绘制副本:

Here is how to make it work: just do a copy of the circle and plot the copy:

第一个导入副本:

from copy import copy

然后,而不是这样做:

for c in Liste_circles:
    ax.add_patch(c)

我们必须做的:

for c in Liste_circles:
   new_c=copy(c)
   ax.add_patch(new_c)

这样,我们将不会绘制相同的圆圈(=同一位艺术家),而是绘制其副本

This way we won't plot the same circle (= the same artist) but its copy

这篇关于不能把单个艺术家放在一个以上的人物中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆