如何将rgb颜色值传递给python';什么是matplotlib事件图?

如何将rgb颜色值传递给python';什么是matplotlib事件图?,python,matplotlib,colors,Python,Matplotlib,Colors,我只是尝试使用matplotlib的eventplot以特定的颜色绘制一些记号。我正在Jupyter笔记本中运行Python3,内嵌%matplotlib 下面是一个示例代码: import numpy as np import matplotlib.pyplot as plt spikes = 100*np.random.random(100) plt.eventplot(spikes, orientation='horizontal', linelengths=0.9, color=

我只是尝试使用matplotlib的eventplot以特定的颜色绘制一些记号。我正在Jupyter笔记本中运行Python3,内嵌%matplotlib

下面是一个示例代码:

import numpy as np
import matplotlib.pyplot as plt    
spikes = 100*np.random.random(100)
plt.eventplot(spikes, orientation='horizontal', linelengths=0.9, color=[0.3,0.3,0.5])
它输出以下错误:

ValueError: colors and positions are unequal sized sequences
发生此错误可能是因为我没有提供与数据长度相同的颜色列表(但我不希望它们都是相同的颜色!)。当我使用诸如“深红色”或“兰花”之类的颜色字符串时,它也会给出一个错误。但当我使用一个简单的单字母字符串,如“r”时,它就起作用了

我真的只限于使用非常有限的一组单字母颜色字符串'r','b','g','k','m','y',等等吗。。。或者在使用此eventplot时制作一个长颜色列表?

根据:

可以传递(r,g,b)或(r,g,b,a)元组,其中r,g,b 和a在[0,1]范围内

#用于三个打印变量的列表
df=数据[['x','y','z']]
颜色主题=[(52/235,235/235,86/235),(52/235,70/235,235/235),
(165/235, 52/235, 235/235)]           
df.plot(颜色=颜色主题)
#其中,分子是R、G、B数字

#python只在数字中使用RGB,当提供
color=[0.3,0.3,0.5]
时,您希望看到什么?当您提供一个列表作为颜色参数时,matplotlib理解您希望第一个事件为颜色[0],第二个事件为颜色[1],…我希望每个记号的颜色由[0.3,0.3,0.5]定义,这是一种深海军蓝,比默认的“b”更容易在眼睛上看到。我真的需要在每个元素都是[0.3,0.3,0.5]的情况下创建一个相同长度的数据列表吗?不,你不需要,试着传递
color=(0.3,0.3,0.5)
,这样作为元组就可以了。你确定吗?对你有用吗?使用元组对我仍然不起作用:(是的,谢谢你,它起作用了!请注意为
.plot
函数尝试此颜色语法的人。在这种情况下,请删除元组列表,但只给出一个RGB值的元组。我确实相信最大RGB数量实际上是256,因为它是介于0和255之间的范围
import numpy as np
import matplotlib.pyplot as plt

spikes = 100*np.random.random(100)
plt.eventplot(spikes, orientation='horizontal', linelengths=0.9, color = [(0.3,0.3,0.5)])

plt.show()
# for a list of three plotted variables

df = data[['x', 'y', 'z']]
color_theme=[(52/235, 235/235, 86/235), (52/235, 70/235, 235/235), 
(165/235, 52/235, 235/235)]           
df.plot(color=color_theme)

# where numerators are the R,G,B numbers
# python only uses RGB in numbers <1
# denominator is obviously the max RGB quantity on a normal RGB scale