如何在Python中绘制带有空圆圈的散点图?
在Python中,使用Matplotlib,如何绘制带有空圆圈的散点图?目标是在 一些 已由 scatter()
绘制的彩色圆盘周围绘制空圆圈,以便突出显示它们,理想情况下无需重新绘制彩色圆圈。
我尝试了facecolors=None
,但没有成功。
In Python, with Matplotlib, how can a scatter plot with empty circles be plotted? The goal is to draw empty circles around some of the colored disks already plotted by scatter()
, so as to highlight them, ideally without having to redraw the colored circles.
I tried facecolors=None
, to no avail.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
从分散文档:
尝试以下操作:
注意:有关其他类型的绘图,请参阅这篇文章介绍了
markeredgecolor
和markerfacecolor< /代码>。
From the documentation for scatter:
Try the following:
Note: For other types of plots see this post on the use of
markeredgecolor
andmarkerfacecolor
.这些有用吗?
或使用plot()
Would these work?
or using plot()
这是另一种方法:这会向当前轴、绘图或图像或其他任何内容添加一个圆圈:
(图片被压缩为椭圆,因为
imshowspect="auto"
)。Here's another way: this adds a circle to the current axes, plot or image or whatever :
(The circles in the picture get squashed to ellipses because
imshow aspect="auto"
).基于 Gary Kerr 的示例以及此处的建议可以使用以下代码创建与指定值相关的空圆圈:
Basend on the example of Gary Kerr and as proposed here one may create empty circles related to specified values with following code:
在 matplotlib 2.0 中有一个名为
fillstyle
的参数这可以更好地控制标记的填充方式。
就我而言,我将它与错误栏一起使用,但它通常适用于标记
http://matplotlib.org/api/_as_gen/matplotlib.axes.Axes .errorbar.html
fillstyle
接受以下值: '左' | '对' | '底部' | '顶部' | 'none']使用
fillstyle
时需要记住两件重要的事情,1)如果 mfc 设置为任何类型的值,它将优先,因此,如果您确实将 fillstyle 设置为 'none' '它不会生效。
因此,请避免将 mfc 与 fillstyle 结合使用
2) 您可能想要控制标记边缘宽度(使用
markeredgewidth
或mew
),因为如果标记相对较小且边缘宽度很厚,标记看起来会像填充的,即使它们没有填充。以下是使用错误栏的示例:
In matplotlib 2.0 there is a parameter called
fillstyle
which allows better control on the way markers are filled.
In my case I have used it with errorbars but it works for markers in general
http://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.errorbar.html
fillstyle
accepts the following values: [‘full’ | ‘left’ | ‘right’ | ‘bottom’ | ‘top’ | ‘none’]There are two important things to keep in mind when using
fillstyle
,1) If mfc is set to any kind of value it will take priority, hence, if you did set fillstyle to 'none' it would not take effect.
So avoid using mfc in conjuntion with fillstyle
2) You might want to control the marker edge width (using
markeredgewidth
ormew
) because if the marker is relatively small and the edge width is thick, the markers will look like filled even though they are not.Following is an example using errorbars:
所以我假设您想强调一些符合特定标准的要点。您可以使用 Prelude 的命令使用空圆圈对突出显示的点进行第二次散点图,并第一次调用以绘制所有点。确保 s 参数足够小,以便较大的空心圆能够包围较小的实心圆。
另一种选择是不使用散点图并使用圆/椭圆命令单独绘制面片。这些位于 matplotlib.patches 中,这里是一些有关如何绘制圆圈的示例代码矩形等
So I assume you want to highlight some points that fit a certain criteria. You can use Prelude's command to do a second scatter plot of the hightlighted points with an empty circle and a first call to plot all the points. Make sure the s paramter is sufficiently small for the larger empty circles to enclose the smaller filled ones.
The other option is to not use scatter and draw the patches individually using the circle/ellipse command. These are in matplotlib.patches, here is some sample code on how to draw circles rectangles etc.