python画图颜色代码rgb_如何将rgb颜色值传递给python的matplotlib事件图?

我只是尝试用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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值