matplotlib: coloring line plots by iteration-dependent gray scale

夙愿已清 提交于 2019-12-06 09:48:55

See: http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes.plot

E.g. you can set plt.plot(x, yint(x), color=(0.5, 0.5, 0.5)) for a gray line. You can set the values up however you like (0.0 is black, 1.0 is white). A simple example:

import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import interp1d

for t in np.arange(0.,2., 0.4):
    x = np.linspace(0.,4, 100)
    y = np.sin(x-2*t) + 0.01 * np.random.normal(size=x.shape)
    yint = interp1d(x, y)
    print t
    col = (t/2.0, t/2.0, t/2.0)
    plt.plot(x, yint(x), color=col)

plt.show()

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!