Matplotlib:散点图,带有用于边缘颜色但没有面颜色的颜色图 [英] Matplotlib: scatter plot with colormaps for edgecolor but no facecolor

查看:129
本文介绍了Matplotlib:散点图,带有用于边缘颜色但没有面颜色的颜色图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个带有颜色图的散点图,用于边缘颜色但没有面颜色.当我使用 facecolor='None' 时,它不起作用.

I want to have a scatter plot with colormap for edgecolors but no facecolors. When I use facecolor='None', it does not work.

import numpy as np
import matplotlib.pyplot as plt


N = 50
x = np.random.rand(N)
y = np.random.rand(N)
colors = np.random.rand(N)
area = np.pi * (15 * np.random.rand(N))**2  # 0 to 15 point radii

plt.scatter(x, y, s=area,c=colors,facecolors='None',cmap="gist_rainbow", alpha=0.5)
plt.show()

有解决方案吗?

推荐答案

c 参数将同时影响facecolor和edgecolor,而 facecolor edgecolor 因此被忽略.

The c argument will affect facecolor and edgecolor simultaneouly, the arguments facecolor and edgecolor are hence ignored.

解决方案不是将 c 参数与颜色图一起使用,而是单独使用 facecolorsedgecolors.在这种情况下,facecolors 可以设置为 "None" 并且 edgecolors 可以被赋予一个要使用的颜色列表.

A solution would be not to use the c argument together with a colormap, but instead use facecolors and edgecolors alone. In this case facecolors can be set to "None" and edgecolors can be given a list of colors to use.

要创建此列表,可以应用相同的颜色图.

To create this list, the same colormap can be applied.

c = plt.cm.gist_rainbow(colors)
plt.scatter(x, y, s=area,facecolors="None", edgecolors=c, lw=1,alpha=0.5)

完整示例:

import numpy as np
import matplotlib.pyplot as plt

N = 50
x = np.random.rand(N)
y = np.random.rand(N)
colors = np.random.rand(N)
area = np.pi * (15 * np.random.rand(N))**2  # 0 to 15 point radii

c = plt.cm.gist_rainbow(colors)
plt.scatter(x, y, s=area,facecolors="None", edgecolors=c, lw=2,alpha=0.5)
plt.show()

这篇关于Matplotlib:散点图,带有用于边缘颜色但没有面颜色的颜色图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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