【发布时间】:2018-03-01 22:40:28
【问题描述】:
我有一个有 6 个切片的饼图,我期待更改饼图中出现的默认颜色。
据我所知,使用.fillColor 我可以更改切片的颜色。
pie_chart = Drawing(200, 200)
pc = Pie()
pc.x = 65
pc.y = 15
pc.width = 150
pc.height = 150
pc.data = [65,13,12,9,1]
pc.labels = ['Name','Another','Yet Another','Test','Stack','Flow')
We can change the color of a slice using:
pc.slices[1].fillColor=red
但是我期待更改所有 6 个切片的颜色,因此我尝试了:
colores=[red,brown,violet,yellow,green,pink]
pc.slices.fillColors=colores
它会输出错误:
AttributeError: Illegal attribute 'fillColors' in class WedgeProperties
我的问题是:如何在一行代码中更改每个切片的颜色?有什么属性可以这样做吗?
【问题讨论】:
-
你看过the documentation吗?那里的例子特别包括这个。
-
如果一次只能设置一种颜色,请使用循环。