matplotlib分散边缘而不指定edgecolor [英] matplotlib scatter edge without specifying edgecolor

查看:105
本文介绍了matplotlib分散边缘而不指定edgecolor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在看来,默认的散点图标记是没有边的实心圆.我想要一个带有边缘且facecolor ="none"的标记. 但是,如果未指定facecolor ="none"但edgecolor,则该图为空. 我希望标记可以使用多种不同的颜色,但是不必关心哪种标记具有哪种颜色.

It seems that now the default scatter plot marker is a filled circle without an edge. I want a marker with an edge and with facecolor="none". But if facecolor="none" but edgecolor is not specified, then the plot is empty. I want markers be in multiple distinct colors, but don't care which one has which color.

我怎样才能打开"边缘?

How can I just "turn on" the edges?

推荐答案

有两种方法可以生成空的或空心的散布标记:

There are two ways to produce empty or hollow scatter markers:

您可以关闭"面部,而不是仅开启"边缘.因此,为了使散射标记的面色透明,可以将生成的PolyCollecton的面色设置为"none".

Instead of "just turning on" the edges, you may "turn off" the faces. So in order to make the facecolors of scatter markers transparent you may set the facecolor of the resulting PolyCollecton to "none".

sc = ax.scatter(...)
sc.set_facecolor("none")

这与sc = ax.scatter(x,y, c=x, facecolor="none")不同,因为c自变量会覆盖facecolor.

This is different from sc = ax.scatter(x,y, c=x, facecolor="none"), because the c argument overwrites the facecolor.

完整示例:

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0,2*np.pi,20)
y = np.sin(x)

fig, ax=plt.subplots()
sc = ax.scatter(x,y, c=x, cmap="nipy_spectral")
sc.set_facecolor("none")

plt.show()

另一种选择是使用非填充标记.这将仅在边缘具有其面色.例如, STIX字体(另请参见此问题)

A different option is to use a non-filled marker. This would have its facecolor only at the edge. An example may be marker="$\u25EF$" from the STIX font (also see this question)

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0,2*np.pi,20)
y = np.sin(x)

fig, ax=plt.subplots()

sc = ax.scatter(x,y, c=x, marker="$\u25EF$", cmap="nipy_spectral")

plt.show()

注意:在python 2中,您需要改为使用marker=ur"$\u25EF$".

这篇关于matplotlib分散边缘而不指定edgecolor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆