【问题标题】:color every point of path based on curvature using python使用python根据曲率为每个路径点着色
【发布时间】:2018-02-06 00:08:26
【问题描述】:

如何在散点图中对颜色进行编码,当变量曲率为 0 时,将每个点 (x,y) 着色为黑色,然后随着曲率越高淡出绿色,负数淡出红色?

【问题讨论】:

  • 我认为这不是在这里发布问题的正确方式。您可能想要添加 sn-p/whole 您的代码或您迄今为止尝试过的内容。
  • 我刚刚发现这可以使用 matplotlib.pyplot.scatter 来完成,但我不知道如何定义颜色图

标签: python plot colors point scatter


【解决方案1】:

你的问题似乎提出了几个问题。

首先,您必须计算(x,y) 数据的曲率。我建议你看看here

然后,也许您可​​以查看 matplotlib 文档中的所有 available colomaps。尽管有可能,但可能没有必要创建自己的颜色图。

最后,您的代码将类似于:

import numpy as np
import matplotlib.pyplot as plt

x = range(10)
y = np.random.rand(10) # generate random points
curvature = range(10) #compute your curvature here

plt.figure()
plt.scatter(x, y, s=20, c=curvature, cmap=plt.cm.seismic)
#perhaps you want to link points:
plt.plot(x,y)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-14
    • 2019-12-14
    • 2019-01-21
    • 1970-01-01
    • 1970-01-01
    • 2016-06-17
    • 2022-01-24
    相关资源
    最近更新 更多