方法
import matplotlib.patheffects as pe
plt.plot(x, y, color='k', lw=2, path_effects=[pe.Stroke(linewidth=5, foreground='g'), pe.Normal()])
例子
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.patheffects as pe
# setup data
x = np.arange(0.0, 1.0, 0.01)
y = np.sin(2*2*np.pi*x)
# create line plot including an outline (stroke) using path_effects
plt.plot(x, y, color='k', lw=2, path_effects=[pe.Stroke(linewidth=5, foreground='g'), pe.Normal()])
## shadow
## plt.plot(x, y, color='k', lw=2, path_effects=[pe.SimpleLineShadow(shadow_color='g'), pe.Normal()])
# custom plot settings
plt.grid(True)
plt.ylim((-2, 2))
plt.legend(['sine'])
plt.show()
参考:https://www.cnpython.com/qa/67939
|