我想使用eventplot根据他们的标签给一些1D点上色。 以下是我想做的一个简单示例:
my_arr = [1.5, 2.4, 5.6]
my_colors = ["g", "b", "g"]
plt.eventplot(my_arr, colors=colors1)
这是我得到的stacktrace:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-82-0a7ce5b07a8c> in <module>
12 my_arr = [1.5, 2.4, 5.6]
13 my_colors = ["g", "b", "g"]
---> 14 plt.eventplot(my_arr, colors=colors1)
~/anaconda3/lib/python3.7/site-packages/matplotlib/pyplot.py in eventplot(positions, orientation, lineoffsets, linelengths, linewidths, colors, linestyles, data, **kwargs)
2620 linelengths=linelengths, linewidths=linewidths, colors=colors,
2621 linestyles=linestyles,
-> 2622 **({"data": data} if data is not None else {}), **kwargs)
2623
2624
~/anaconda3/lib/python3.7/site-packages/matplotlib/__init__.py in inner(ax, data, *args, **kwargs)
1436 def inner(ax, *args, data=None, **kwargs):
1437 if data is None:
-> 1438 return func(ax, *map(sanitize_sequence, args), **kwargs)
1439
1440 bound = new_sig.bind(ax, *args, **kwargs)
~/anaconda3/lib/python3.7/site-packages/matplotlib/axes/_axes.py in eventplot(self, positions, orientation, lineoffsets, linelengths, linewidths, colors, linestyles, **kwargs)
1460 'sequences')
1461 if len(colors) != len(positions):
-> 1462 raise ValueError('colors and positions are unequal sized '
1463 'sequences')
1464 if len(linestyles) != len(positions):
ValueError: colors and positions are unequal sized sequences
我已经检查了文档和几个主题,但没有弄清楚。 我错过了什么
positions变量
my_arr
应该是一个列表列表,其中每个内部列表包含属于同一颜色组的事件。 颜色变量my_colors
应该只列出每种颜色一次,以便len(my_arr)==len(my_colors)
。下面的代码应该有效:要使其看起来像1D,您可能需要将
lineoffsets=0
添加到eventplot
的输入中:(输入错误提示:您似乎使用不同的名称来引用
my_colors
later,colors1
)相关问题 更多 >
编程相关推荐