python的曲线平滑工具,及python画一条线中包含不同粗细不同颜色的画线方法
from scipy.signal import savgol_filter
import matplotlib.pyplot as plt
cc = savgol_filter(c, 99, 1)
plt.plot(c)
plt.plot(cc)
plt.show()
from matplotlib.collections import LineCollection import numpy as np import math import matplotlib.pyplot as plt pi = 3.1415 x = np.linspace(0, 4*pi, 100) y = [math.cos(xx) for xx in x] lwidths = abs(x) color = [] for i in range(len(y)): if i < 5: color.append('#FF0000') else: color.append('#000000') print(x) print(y) print('--------------------------------------') points = np.array([x, y]).T.reshape(-1, 1, 2) print(points) print('--------------------------------------') segments = np.concatenate([points[:-1], points[1:]], axis=1) print(segments) lc = LineCollection(segments, linewidths=lwidths, color=color) ax = plt.axes() ax.set_xlim(min(x), max(x)) ax.set_ylim(min(y), max(y)) ax.add_collection(lc) plt.show() ''' fig, a = plt.subplots() a.add_collection(lc) a.set_xlim(0, 4*pi) a.set_ylim(-1.1, 1.1) fig.show() '''
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
支付宝扫一扫捐赠
支付宝扫一扫捐赠
微信公众号: 共鸣圈
欢迎讨论,邮件: 924948$qq.com 请把$改成@
QQ群:263132197
QQ: 924948