【问题标题】:matplotlib not changing scatter point colors if they are assigned the first time如果第一次分配它们,matplotlib 不会改变散点颜色
【发布时间】:2011-10-31 15:09:50
【问题描述】:

在以下最小示例中,我创建了 1 点散点图,然后使用 Collection.set_color 更改循环中点的颜色。如果我在第一次调用 scatter 时设置颜色,set_color 将不会改变它的面颜色(只有边缘颜色),而如果我在创建散点图时没有指定它,面颜色会改变根据set_color.

from pylab import *
from numpy import *
coll=scatter([0],[0],s=500,c=[.1]) # omit c=[.1] here to have face color changing later
ion(); show()
for a in linspace(.1,.9):
    coll.set_color(coll.get_cmap()(a))
    draw()

这是一个错误,还是我在文档中遗漏了什么?

【问题讨论】:

  • 是的,在 win 7 64bit 中复制,mpl 1.0.1
  • 在这里按预期工作。 Win7 32bit, mpl 1.1.0.
  • 我在 matplotlib 上遇到过类似的问题——就像一个散点只能被分配一次颜色并且永远不会被覆盖。

标签: python matplotlib


【解决方案1】:

我会说这是该 matplotlib 版本的错误/限制。 我尝试了以下代码:

matplotlib 1.0.1 (ActivePython 2.6.7, win7 64bit)           --> reproduced the behavior
matplotlib 1.1.0.dev (ActivePython 3.2.2, winXP, 32bit)     --> works as expected

还有来自 Avaris 的评论说他使用 mpl 1.1.0 (win7, 32bit) 得到了预期的行为

所以如果可能的话,我建议你升级你的安装

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-18
    • 1970-01-01
    • 2022-12-12
    • 2017-07-19
    • 1970-01-01
    • 2021-12-26
    • 1970-01-01
    • 2014-09-10
    相关资源
    最近更新 更多