Python 渐变色绘图

用渐变色绘图。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from __future__ import division
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.rcParams['font.family'] = 'Helvetica Neue'

"""Draw lines using colors ranging from startcolor to endcolor
"""

# Colors(R, G, B) should be non-negative numbers no more than 1.
start = np.array([1, 0, 0])
end = np.array([0, 0, 1])
n = 5
step = (end-start) / n

x = np.arange(0, 10, 0.01)

plt.axis([0, 10, -1.2, 1.2])
plt.xlabel('$x$')
plt.ylabel('$y$')
for i in range(n + 1):
    y = np.sin(x - i/2)
    c = start + i*step
    plt.plot(x, y, color=c)
plt.show()

结果:

Image Title

2014-05-09 15:54211PythonMatplotlib
comments powered by Disqus