如何绘制颜色列表饼图
你好,我有一个字典,其中 3-int-tuple 表示颜色(作为键),还有一个 int 表示图像中该颜色出现的次数(作为值),
例如,这是一个具有 3 种颜色的 4x4 像素图像: {(87, 82, 44): 1, (255, 245, 241): 11, (24, 13, 9): 4}
我想绘制列表 [1,11,4] 的饼图,其中每个饼图的切片涂上了正确的颜色..我该怎么办?
hi i have a dict with 3-int-tuple representing color (as key) and an int representing the numbers of occurences of that color in an image (as value)
for exemple, this is a 4x4 pixels image with 3 colors:
{(87, 82, 44): 1, (255, 245, 241): 11, (24, 13, 9): 4}
i want to plot a pie chart of list [1,11,4] in which each slice of the piechart is colored with the right color.. how can i do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更新:其他答案来自Paul的要好得多,但我只是编辑原来的答案,直到它基本上相同:)(我无法删除这个答案,因为它已被接受。)实际上没有任何意义
。你想要吗?我刚刚采用了 matplotlib 文档中的示例 并将数据转换为参数
pie()
期望:结果如下所示:
Update: the other answer from Paul is much better but there's not really any point in me just editing my original answer until it's essentially the same :) (I can't delete this answer because it's accepted.)
Does this do what you want? I just took an example from the matplotlib documentation and turned your data into parameters that
pie()
expects:The result looks like this:
马克领先我 5 分钟,所以分数应该归于他,但无论如何,这是我的答案(几乎相同,但更简洁):
Mark beat me by 5 minutes, so points should go to him, but here's my (nearly identical, but more terse) answer anyway: