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

问题描述 投票:32回答:3

我正在使用pyplot.plot生成散点图(而不是散点图 - 我对色图有困难)

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

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

python matplotlib
3个回答
42
投票

要删除标记的轮廓并调整其颜色,请分别使用markeredgewidth(aka mew)和markeredgecolor(aka 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)

这产生:plot result

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


6
投票

来自pyplot API docs

markeredgecolor或mec任何matplotlib颜色

例:

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

产量:

这就是你要找的东西吗?


0
投票

这在matplotlib.axes.Axes.scatter发现的https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.scatter.html文档中有所概述

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

 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’.

您可能也想要更改它。如果为None,则默认为rcParams lines.linewidth。

© www.soinside.com 2019 - 2024. All rights reserved.