简体   繁体   中英

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

截屏

Has anyone else encountered this, and maybe found a solution? I'm using 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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