0

I am trying to make a custom plot using matplotlib. I have got the legends but for the point marker there is a line and white halo around the point. Is there any way where I can add only the point marker by removing the line and halo behind and around the marker? The script I used is.

from matplotlib.patches import Patch
from matplotlib.lines import Line2D

legend_elements = [Line2D([0], [0], color='b', lw=4, label='Line'),
                   Line2D([0], [0], marker='o', color='w', label='location',
                          markerfacecolor='g', markersize=10),
                   Patch(facecolor='orange', edgecolor='r',
                         label='Color Patch')]

# Create the figure
fig, ax = plt.subplots()
ax.set_facecolor('xkcd:black')

ax.legend(handles=legend_elements, loc='center')

plt.show()

Output plot

enter image description here

enter image description here

Gokul Anand
  • 177
  • 12
  • Did you try `color='none'`, e.g. `Line2D([0], [0], marker='o', color='none', label='Scatter', markerfacecolor='g', markersize=10)`? – JohanC Dec 15 '20 at 09:31
  • Have a look at [here](https://stackoverflow.com/questions/21285885/remove-line-through-marker-in-matplotlib-legend). – rftr Dec 15 '20 at 09:35
  • @johnC Colour 'none' leaves a black circle around my point – Gokul Anand Dec 15 '20 at 09:59

1 Answers1

1

Just add linestyle/ls = '' in 2nd argument of legend_element

#Updated code

from matplotlib.patches import Patch

from matplotlib.lines import Line2D

                legend_elements = [Line2D([0], [0], color='b', lw=4, label='Line'),
               Line2D([0], [0], marker='o', color='w', label='location',
                      markerfacecolor='g', markersize=10, ls = ''),
               Patch(facecolor='orange', edgecolor='r',
                     label='Color Patch')]

fig, ax = plt.subplots() ax.set_facecolor('xkcd:black')

ax.legend(handles=legend_elements, loc='center')

plt.show()

output image