如何将RGB颜色值传递给Python的Matplotlib eventplot?
为了将RGB颜色值传递给Python的Matplotlib eventplot,请按照以下步骤进行操作。
步骤
- 设置图形大小并调整子图之间和周围的填充。
- 创建一个一维数组 pos ,用于定义一个事件序列的位置。
- 创建颜色元组列表 r,g,b。
- 在给定位置处绘制相同的平行线。
- 使用 show() 方法显示图形。
示例
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
pos = 10 * np.random.random(100)
colors = [(0.75, 0.50, 0.25)]
plt.eventplot(pos, orientation='horizontal',
linelengths=0.75, color=colors)
plt.show()
输出
您可以更改 colors 中的R,G,B值以获取图形中的不同颜色。