为什么matplotlib.PatchCollection与补丁的颜色混乱? [英] Why is matplotlib.PatchCollection messing with color of the patches?

查看:128
本文介绍了为什么matplotlib.PatchCollection与补丁的颜色混乱?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一些补丁,像这样 -

I make a number of patches like so -

node.shape = RegularPolygon((node.posX, node.posY),
                            6,
                radius = node.radius,
                                    edgecolor = 'none',
                                    facecolor = node.fillColor,
                                    zorder = node.zorder)

node.brushShape = RegularPolygon((node.posX, node.posY),
                            6,
                node.radius * 0.8,
                linewidth = 3,
                                    edgecolor = (1,1,1),
                                    facecolor = 'none',
                                    zorder = node.zorder)

最初我只是把它们直接放到轴上 -

And originally I was just putting them straight onto my axis like this -

self.plotAxes.add_artist(node.shape)
self.plotAxes.add_artist(node.brushShape)

这工作正常。但现在我想把它们放入一个PatchCollection并把PatchCollection放到轴上。然而,当我这样做,我的形状只是蓝色。我不明白怎么只是把一个集合改变颜色不知何故。任何人都可以帮助我,我需要做什么,以保持我输入的颜色值作为面部颜色的补丁吗?

That worked fine. But now I want to put them into a PatchCollection and put that PatchCollection onto the axis. However, when I do that, all of my shapes are just blue. I don't understand how just putting into a collection is changing the color somehow. Can anyone help me out on what I need to be doing to keep the color values that I input as the faceColor for the patches?

新代码是 -

node.shape = RegularPolygon((node.posX, node.posY),
                        6,
            radius = node.radius,
                                edgecolor = 'none',
                                facecolor = node.fillColor,
                                zorder = node.zorder)

node.brushShape = RegularPolygon((node.posX, node.posY),
                        6,
            node.radius * 0.8,
            linewidth = 3,
                                edgecolor = (1,1,1),
                                facecolor = 'none',
                                zorder = node.zorder)

self.patches.append(node.shape)
self.patches.append(node.brushShape)


self.p = PatchCollection(self.patches) 
self.plotAxes.add_collection(self.p) 


推荐答案

self.p = PatchCollection(self.patches, match_original=True) 

默认情况下,补丁集合覆盖给定的颜色( doc ),以便能够应用颜色映射,循环颜色等。这是一个集合 level特性(以及散点图后面的代码有什么强大功能)。

By default patch collection over-rides the given color (doc) for the purposes of being able to apply a color map, cycle colors, etc. This is a collection level feature (and what powers the code behind scatter plot).

这篇关于为什么matplotlib.PatchCollection与补丁的颜色混乱?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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