Python 在matplotlib中使用pyplot.plot时如何删除圆形标记的轮廓

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28403179/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 03:13:42  来源:igfitidea点击:

How to remove outline of circle marker when using pyplot.plot in matplotlib

pythonmatplotlib

提问by Toam

I'm producing a scatter plot using pyplot.plot (instead of scatter - I'm having difficulties with the colormap)

我正在使用 pyplot.plot (而不是 scatter - 我在使用颜色图时遇到困难)生成散点图

I am plotting using the 'o' marker to get a circle, but the circle always has a black outline.

我正在使用“o”标记绘制一个圆圈,但圆圈总是有一个黑色的轮廓。

How do I remove the outline, or adjust its colour?

如何去除轮廓或调整其颜色?

采纳答案by jrd1

To remove the outline of a marker, and adjust its color, use markeredgewidth(aka mew), and markeredgecolor(aka mec) respectively.

要移除标记的轮廓并调整其颜色,请分别使用markeredgewidth(aka mew) 和markeredgecolor(aka mec)。

Using this as a guide:

使用这个作为指导

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0, 5, 0.1)
y = np.sin(x)

plt.plot(x,
         y,
         color='blue',
         marker='o',
         fillstyle='full',
         markeredgecolor='red',
         markeredgewidth=0.0)

This produces: plot result

这产生: 绘图结果

As you notice, even though the marker edge color is set, because the width of it is set to zero it doesn't show up.

如您所见,即使设置了标记边缘颜色,因为它的宽度设置为零,它也不会显示。

回答by Andrey Sobolev

From the pyplotAPI docs:

来自pyplotAPI 文档

markeredgecolor or mec any matplotlib color

markeredgecolor 或 mec 任何 matplotlib 颜色

Example:

例子:

In [1]: import matplotlib.pyplot as plt

In [2]: import numpy as np

In [3]: x = np.linspace(0,1,11)

In [4]: y = x * x

In [5]: plt.plot(x,y,'o',color="red", ms=15, mec="red")
Out[5]: [<matplotlib.lines.Line2D at 0x34e1cd0>]

In [6]: plt.show()

Yields: Figure

产量: 数字

Is that what you're looking for?

这就是你要找的吗?

回答by nicholasericksen

This is outlined in matplotlib.axes.Axes.scatterdocumentation found at https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.scatter.html

matplotlib.axes.Axes.scatterhttps://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.scatter.html中的文档中进行了概述

It specifies that line edge colors for scatter plot markers can be set with

它指定散点图标记的线边缘颜色可以设置为

 edgecolors : color or sequence of color, optional, default: ‘face'
 The edge color of the marker. Possible values:

 - ‘face': The edge color will always be the same as the face color.
 - ‘none': No patch boundary will be drawn.
 - A matplotib color.

 For non-filled markers, the edgecolors kwarg is ignored and forced to ‘face' internally.

The width of the line edges can be specified with

线边缘的宽度可以用

`linewidths` : scalar or array_like, optional, default: None

The linewidth of the marker edges.

Note: The default edgecolors is ‘face'.

You may want to change this as well. If None, defaults to rcParams lines.linewidth.

您可能也想更改此设置。如果没有,默认为 rcParams lines.linewidth。