我只是尝试用matplotlib的eventplot绘制一些特定颜色的刻度线.我在Jupyter笔记本中使用%matplotlib内联运行Python 3.
这是一个示例代码:
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
错误发生的原因可能是因为我没有提供与数据长度相同的颜色列表(但我不想让它们只是相同的颜色!).当我使用像’crimson’或’orchid’这样的颜色字符串时,它也会出错.但是当我使用像’r’这样的简单单字母字符串时它会起作用.
我真的只限于使用非常有限的单字母颜色字符串’r’,’b’,’g’,’k’,’m’,’y’等…或者制作一个长颜色列表使用此事件时?
解决方法:
you can pass an (r, g, b) or (r, g, b, a) tuple, where each of r, g, b
and a are in the range [0,1].
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()
标签:python,colors,matplotlib