6

I'm plotting using the Matplotlib scatter plotter. For the markers I'd ideally like the outline of a circle with a dot inside (outside circle makes it clear there's something there, the dot is then more precise). I can achieve this if I simply plot it twice (once with the outline then again with the dot) but then my legend isn't correct. So my question is, is there any way to do this? Or am I looking for a solution that doesn't exist?

Example code:

import matplotlib.pyplot as plt

fig1 = plt.figure()
ax1 = fig1.add_subplot(111)


x_data = [0.5, 1, 1.5]
y_data = [0.06, 0.06, 0.01]


ax1.scatter(x_data, y_data, label= 'Example legend entry.', s=80, marker='o', facecolors='none', edgecolors='black')
ax1.scatter(x_data, y_data, label= 'Example legend entry.', s=10, marker='o', color='black')


plt.gcf().subplots_adjust(bottom=0.08, top=0.95, left=0.05, right=0.84)


ax1.legend(loc='center left', bbox_to_anchor=(1, 0.5), fancybox=True, ncol=1, fontsize=17, labelspacing=1)


mng = plt.get_current_fig_manager()
mng.window.showMaximized()

plt.show()

And the example plot: Example plot

So yeah, would like something like those markers but with the ability to have them like that on the legend (unlike how it is currently split up into the two parts).

If any further information or clarification is needed, just ask. Thanks in advance for any/all help!

Clarification: I'm not sure I explained my goal well enough. I know I can get rid of one of the legends, but what I'm trying to achieve is a single legend entry with the combined marker (i.e. a circle with a 'dot' inside it). If I can't achieve then yes I'll just disable the legend for the outer circle but would quite like to get the marker used (which is a combination of two markers) on the plot to also be used on the legend.

3 Answers 3

9

You can use latex marker like that :

ax1.scatter(x_data, y_data, label= 'Example legend entry.', s=80, marker=r'$\odot$', facecolors='none', edgecolors='black')

And then plot your graph only one time.

1
  • Ah, perfect! that's exactly what I was after. I'd been searching to see if there was a "circle with a dot" marker and couldn't find anything but it never even crossed my mind to think of latex! Thanks a million for the help!
    – Steve
    Commented Oct 15, 2015 at 15:15
0

Have you tried removing the label from the circle? I used altered your code so that your first plot of the larger circles does not have a label. ax1.scatter(x_data, y_data, s=80, marker='o', facecolors='none', edgecolors='black')

This worked for me, but perhaps not for you?

1
  • Hey, thanks for the reply. I don't think I explained my goal well enough originally so I've added a clarification. Basically I wish to combine the two markers on the legend like I have on the plot. So on the legend there would be one entry with the marker of a circle with a 'dot' inside.
    – Steve
    Commented Oct 15, 2015 at 15:10
0

You can mark your scatter plots and include only one in your legend:

Here's how :

a_ = ax1.scatter(x_data, y_data, label= 'Example legend entry.', s=80, marker='o', facecolors='none', edgecolors='black')
b_ = ax1.scatter(x_data, y_data, label= 'Example legend entry.', s=10, marker='o', color='black')

ax1.legend([a_],["Example legend entry"] , loc='center left', bbox_to_anchor=(1, 0.5), fancybox=True, ncol=1, fontsize=17, labelspacing=1)
1
  • Hey, thanks for the reply. That's not quite what I'm trying to achieve. I don't think I explained my goal well enough in my original post so I've added a clarification. Basically, instead of having one marker or the other (or both separately) on the legend, I'm looking to have one legend entry with the marker being the circle with a 'dot' in the middle (the same as how it's displayed on the plot).
    – Steve
    Commented Oct 15, 2015 at 15:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.