python渐变色代码_如何在matplotlib中绘制渐变色线?

我最近以类似的要求回答了一个问题(使用matplotlib创建了20多种独特的图例颜色)。我在那里展示了您可以映射将线条绘制到颜色图所需的颜色循环。您可以使用相同的过程为每对点获取特定的颜色。

您应该仔细选择颜色图,因为如果颜色图是彩色的,则沿线的颜色过渡可能会显得很剧烈。

或者,您可以更改每个线段的Alpha,范围从0到1。

下面的代码示例中包含一个例程(highResPoints),用于扩展您的随机游走所拥有的点数,因为如果您的点数太少,则过渡可能看起来很困难。我最近提供的另一个答案启发了这段代码:https : //stackoverflow.com/a/8253729/717357

import numpy as np

import matplotlib.pyplot as plt

def highResPoints(x,y,factor=10):

'''

Take points listed in two vectors and return them at a higher

resultion. Create at least factor*len(x) new points that include the

original points and those spaced in between.

Returns new x and y arrays as a tuple (x,y).

'''

# r is the distance spanned between pairs of points

r = [0]

for i in range(1,len(x)):

dx = x[i]-x[i-1]

dy = y[i]-y[i-1]

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值