简体   繁体   English

Matplotlib;散点图标记,圆内点

[英]Matplotlib; Scatter plot marker, dot within circle

I'm plotting using the Matplotlib scatter plotter. 我正在使用Matplotlib散点绘图仪进行绘图。 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: 示例情节: 示例图

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 (ie 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. 如果我无法实现,那么我只是禁用外圈的图例,但是非常希望在绘图上使用标记(也就是两个标记的组合)以用于图例。

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. 然后只绘制一次图表。

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? 这对我有用,但也许不适合你?

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM