python - 是否可以在 matplotlib 中为边缘颜色分配颜色图?

标签 python matplotlib colors

假设需要根据某个变量更改 matplotlib 标记的边缘颜色,是否可以为标记的边缘颜色分配某种离散颜色图? 这类似于通过 cmap 更改标记的面颜色。

当使用绘图范围之外的箭头显示限制时,我似乎无法根据另一个变量来改变箭头颜色。 例如:在下面的代码中,箭头的颜色不会随着 z 的函数而改变。

plt.scatter(x,y, c=z, marker=u'$\u2191$', s=40,cmap=discrete_cmap(4, 'cubehelix') )

最佳答案

您可以使用分散的 edgecolors 参数来完成此操作。

您需要创建一个颜色列表以提供给scatter。我们可以使用您选择的 colormapNormalize 实例来执行此操作,将 z 函数重新缩放为 0-1 范围。

我假设您的 discrete_cmap 函数类似于链接的 here 函数.

import matplotlib.pyplot as plt
import matplotlib.colors as colors
import numpy as np

# def discrete_cmap() is omitted here...

# some sample data
x = np.linspace(0,10,11)
y = np.linspace(0,10,11)
z = x+y

# setup a Normalization instance
norm = colors.Normalize(z.min(),z.max())

# define the colormap
cmap = discrete_cmap(4, 'cubehelix')

# Use the norm and cmap to define the edge colours
edgecols = cmap(norm(z))

# Use that with the `edgecolors` argument. Set c='None' to turn off the facecolor
plt.scatter(x,y, edgecolors=edgecols, c = 'None', marker='o', s=40 )

plt.show()

enter image description here

关于python - 是否可以在 matplotlib 中为边缘颜色分配颜色图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33930784/

相关文章:

python - GLib.idle_add(function) 对不同的函数有不同的策略

python - 如何让 raw_input 以简单、快速的方式接受多个答案

python - python 中的 `locals()` 列表理解错误

python - 根据 BeautifulSoup 中的文字字符串检查 Class 属性?

python-3.x - pandas DatetimeIndex 到 matplotlib x-ticks

python-2.7 - 类似于Matplotlib-Basemap的3D CartoPy

colors - 如何从 wxPython 更改禁用的 TextCtrl 的 ForegroundColour

python - 图中轴矢量场的缩放颤动图

python - Python中的相似颜色检测

javascript - 颜色从蓝色跳到紫色