您可以定义蒙版并使用它们来区分线条所需的"线段".
以下是一个例子.
import numpy as np
import matplotlib.pyplot as plt
# data
x = np.linspace(-10, 10, 1000)
y = np.sin(x)
# 4 segments defined according to some x properties
segment1 = (x<-5)
segment2 = (x>=-5) & (x<0)
segment3 = (x>=0) & (x<5)
segment4 = (x>=5)
plt.plot(x[segment1], y[segment1], '-k', lw=2)
plt.plot(x[segment2], y[segment2], '-g', lw=2)
plt.plot(x[segment3], y[segment3], '-r', lw=2)
plt.plot(x[segment4], y[segment4], '-b', lw=2)
plt.show()
Run Code Online (Sandbox Code Playgroud)

| 归档时间: |
|
| 查看次数: |
1605 次 |
| 最近记录: |