简体   繁体   English

更改Matplotlib散点图的默认边缘颜色

[英]Changing default edge-color for matplotlib scatterplot

I'm looking for a way to change the default edge color for matplotlib scatter plots. 我正在寻找一种更改matplotlib散点图的默认边缘颜色的方法。 Typically, things like that would be set through rcParams , and my understanding is that I should set patch.edgecolor . 通常,类似的事情将通过rcParams设置,我的理解是我应该设置patch.edgecolor However, that doesn't seem to work. 但是,这似乎不起作用。 Here is an example: 这是一个例子:

import numpy as np
from matplotlib import pyplot as plt

x = np.random.randn(50)
y = np.random.randn(50)

with plt.rc_context({'patch.edgecolor': 'white'}):
    plt.subplot(121)
    plt.scatter(x, y)

plt.subplot(122)
plt.scatter(x, y, edgecolors='white')

In the result, I would like to have both subplots look the same, but instead they look like this: 结果,我希望两个子图看起来都一样,但是它们看起来像这样: 我想看什么 Note that I don't want to change the code within the with statement, but instead configure matplotlib such that it uses white edges as a fallback if I don't specify anything else. 请注意,我不想更改with语句中的代码,而是配置matplotlib,以便在我未指定其他任何内容的情况下将其用作白色后备。 Confusingly, the documentation uses a default argument edgecolors=None in the function signature, but states that the default value for edgecolors is 'face' . 令人困惑的是, 文档在函数签名中使用默认参数edgecolors=None ,但声明edgecolors的默认值为'face' How can I change this behaviour? 我该如何改变这种行为?

The rc parameter you're looking for is called 您要查找的rc参数称为

'scatter.edgecolors'

Eg plt.rcParams['scatter.edgecolors'] = "white" or 例如plt.rcParams['scatter.edgecolors'] = "white"
with plt.rc_context({'scatter.edgecolors': 'white'}): . with plt.rc_context({'scatter.edgecolors': 'white'}):

This is a new feature introduced in #12992 and available from matplotlib 3.1 onwards, which will be released very soon. 这是#12992中引入的一项新功能,可从matplotlib 3.1及更高版本开始使用,该功能将很快发布。 As of today, you can install the release candidate via pip install --pre --upgrade matplotlib to get this feature. 从今天开始,您可以通过pip install --pre --upgrade matplotlib候选版本以获得此功能。

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

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