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

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

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

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

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

要删除标记的轮廓并调整其颜色,请使用 markeredgewidth(又名 mew) 和 markeredgecolor(又名 mec)。

使用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)

这会产生:

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

来自pyplot API docs

markeredgecolor or mec any matplotlib color

示例:

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()

产量:

这就是你要找的吗?

https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.scatter.html

matplotlib.axes.Axes.scatter 文档中对此进行了概述

指定散点图标记的线边颜色可以用

设置
 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.

线边的宽度可以用

指定
`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.