1

我想将标志的图像插入到 matplotlib 中的饼图的楔形中。我试图通过图形属性用标志的图像修改每个补丁来做到这一点,但它没有用。最终目标是在每个楔子中放置适当的标志。

http://en.wikipedia.org/wiki/File:Flag_of_Ireland.svg

import matplotlib.pyplot as plt
import collections

iname = r'D:\code\flags\ireland_flag.gif'
image = plt.imread(iname)

gg1 = 'Ireland'
gg2 = 'Ireland'
gg3 = 'Italy'
gg4 = 'Slovakia'
gg5 = 'USA'
gg6 = 'Germany'
gg7 = 'USA'
gg8 = 'USA'

gg = [gg1,gg2,gg3,gg4,gg5,gg6,gg7,gg8]

counter=collections.Counter(gg)

labels = list(counter.keys())
sizes = list(counter.values())

patches, texts, autotexts = plt.pie(sizes, labels=labels, autopct='%1.1f%%', shadow=True)
patches[1].set_figure(image)
plt.axis('equal')
plt.show()
4

0 回答 0