python - 绘制线条时奇怪的 matplotlib 颜色问题

标签 python matplotlib plot

我可能在这里遗漏了一些非常明显的东西,但我尝试了多种组合,但我无法找到这种行为的原因。

我正在运行 Python v2.7.6 和 matplotlib v1.4.3。

我有一个简单的情节:

import matplotlib.pyplot as plt
import numpy as np
x, y = np.random.random(50), np.random.random(50)
plt.plot(x, y, c='red', ls='-', lw=1., label='a', zorder=2)
plt.show()

请注意,根据 c='red',颜色应该为红色。我得到的是:

enter image description here

如果我使用参数的全名color='red',则该行应为红色。如果我删除 c='red' 之后的任何参数,例如:

plt.plot(x, y, c='red', ls='-', lw=1., label='a')
plt.plot(x, y, c='red', ls='-', lw=1., zorder=2)
plt.plot(x, y, c='red', ls='-', label='a', zorder=2)
plt.plot(x, y, c='red', lw=1., label='a', zorder=2)

绘制的线也是红色。

我在这里做了一些非常明显错误的事情还是我偶然遇到了一个奇怪的问题?

<小时/>

添加:

使用:

plt.plot(x, y, c='r', ls='-', lw=1., label='a', zorder=2)

按照建议(即:c='r' 而不是 c='red')对我的系统没有影响,我仍然得到蓝线。

最佳答案

以下信息适用于 Python 3.x 和 matplotlib 1.4.3

c='r'docs 中找到

import matplotlib.pyplot as plt
import numpy as np
x, y = np.random.random(50), np.random.random(50)
plt.plot(x, y, c='r', ls='-', lw=1., label='a', zorder=2)
plt.show()

enter image description here

看起来 color='red'color='r' 似乎可以与 c='r' 配合使用。 c='red' 不会更改线条颜色。

关于python - 绘制线条时奇怪的 matplotlib 颜色问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32956419/

相关文章:

python - Chaco 中的自动填充?

python - 无法在 python 中调度 com 对象

python - 访问位于两个值之间的 pandas 数据框部分

python - matplotlib 中的条件函数绘图

python - pyplot.scatter(c ='red')。无效的语法?

python - 如何使用 sharex 和 sharey 结合方面=等于和可调整 ='box-forced' 在 matplotlib 中创建具有相同比例的子图?

r - 传递参数列表以在 R 中绘图

python - 如何将 pandas 系列 2D 图堆叠成 3D 结构?

Python:确保对象内属性类型的有效方法?

使用列表作为值的 Python 字典,查找具有相同值的其他键