通过matplotlib图例中的标记删除线 [英] Remove line through marker in matplotlib legend
本文介绍了通过matplotlib图例中的标记删除线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个用以下代码生成的matplotlib
图:
I have a matplotlib
plot generated with the following code:
import matplotlib.pyplot as pyplot
Fig, ax = pyplot.subplots()
for i, (mark, color) in enumerate(zip(
['s', 'o', 'D', 'v'], ['r', 'g', 'b', 'purple'])):
ax.plot(i+1, i+1, color=color,
marker=mark,
markerfacecolor='None',
markeredgecolor=color,
label=i)
ax.set_xlim(0,5)
ax.set_ylim(0,5)
ax.legend()
以此为生成的图形:
with this as the generated figure:
我不喜欢图例中标记的线条.我该如何摆脱它们?
I don't like the lines through the markers in the legend. How can I get rid of them?
推荐答案
您可以在plot命令中将linestyle="None"
指定为关键字参数:
You can specify linestyle="None"
as a keyword argument in the plot command:
import matplotlib.pyplot as pyplot
Fig, ax = pyplot.subplots()
for i, (mark, color) in enumerate(zip(
['s', 'o', 'D', 'v'], ['r', 'g', 'b', 'purple'])):
ax.plot(i+1, i+1, color=color,
marker=mark,
markerfacecolor='None',
markeredgecolor=color,
linestyle = 'None',
label=`i`)
ax.set_xlim(0,5)
ax.set_ylim(0,5)
ax.legend(numpoints=1)
pyplot.show()
由于您仅绘制单个点,因此除了图例中看不到线属性.
Since you're only plotting single points, you can't see the line attribute except for in the legend.
这篇关于通过matplotlib图例中的标记删除线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文