python - 我可以给 matplotlib 绘图函数中的一条线添加边框(轮廓)吗?

标签 python plot matplotlib

我尝试:

points = [...]
axe.plot([i[0] for i in points], [i[1] for i in points], linestyle='-', linewidth=10, 
color='black', markeredgewidth=2, markeredgecolor='green')

但我只得到一个黑色轮廓。我怎样才能达到下图所示的效果? black line with green border

最佳答案

如果您绘制一条线两次,它不会出现在图例中。使用patheffects确实更好。这里有两个简单的例子:

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*t)

# 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()])
# custom plot settings
plt.grid(True)
plt.ylim((-2, 2))
plt.legend(['sine'])
plt.show()

enter image description here

或者如果你想添加线条阴影

# create line plot including an simple line shadow using path_effects
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()

enter image description here

关于python - 我可以给 matplotlib 绘图函数中的一条线添加边框(轮廓)吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12729529/

相关文章:

python - 创建线程Python队列?

python - 有没有办法对齐具有相同索引位置的多个列表?

python - 如何使用 matplotlib 创建相等数量的主要和次要 y 轴刻度?

python-3.x - 绘制来自 Pandas Agg 的阴影误差线

python-2.7 - TypeError : 'PathCollection' object is not iterable when adding second legend to plot

python - 从 Python 更新 proc 条目的推荐方法是什么

R:将曲线拟合到点:使用什么线性/非线性模型?

plot - Maxima 中的多个绘图

python - Matplotlib 等值线图绘制两个不同的数据

python - 通过在 PyQt4 中选择/取消选择 QStandardItemModel 在 matplotlib 中显示/隐藏线条