Remove line through legend marker with .plot

You can specify linestyle="None" or linestyle="" as a keyword argument in the plot command. Also, ls= can replace linestyle=.

import matplotlib.pyplot as plt

fig, ax = plt.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)
plt.show()

enter image description here

Since you’re only plotting single points, you can’t see the line attribute except for in the legend.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)