简体   繁体   English

回复:将颜色条添加到带有非实心圆的散点图

[英]Re: Add colorbar to scatterplot with non-filled circles

I know this question has been asked and answered twice before, but those solutions are >4 yrs old now, and don't work for me at least.我知道这个问题之前已经被问过和回答过两次,但这些解决方案现在已经超过 4 年了,至少对我不起作用。 When I try out the this code:当我尝试这段代码时:

import matplotlib.pyplot as plt
x = np.random.random(size=(100,))
y = np.random.random(size=(100,))
c = np.random.random(size=(100,))
fig, ax = plt.subplots()
g = ax.scatter(x, y, marker = 'o',c = c)
g.set_facecolor('none')
fig.colorbar(g)

I get an empty plot like:我得到一个空的 plot,例如:

截屏

Has anyone else encountered this, and maybe found a solution?有没有其他人遇到过这个,也许找到了解决方案? I'm using matplotlib 3.5.1.我正在使用 matplotlib 3.5.1。

I'm having the same issue, but by using a non-filled marker you should get what you want:我有同样的问题,但通过使用非填充标记,你应该得到你想要的:

import matplotlib.pyplot as plt
import numpy as np

x = np.random.random(size=(100,))
y = np.random.random(size=(100,))
c = np.random.random(size=(100,))
fig, ax = plt.subplots()
g = ax.scatter(x, y, marker="$\u25EF$", c=c, s=100)
fig.colorbar(g)

在此处输入图像描述

For further details, look at this answer .有关详细信息, 请查看此答案

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

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