gpt4 book ai didi

Python:matplotlib - 黑白散点图

转载 作者:太空宇宙 更新时间:2023-11-03 13:22:01 24 4
gpt4 key购买 nike

我觉得我在这里遗漏了一些非常明显的东西,但我无法在 pylab 中获得散点图以黑白打印。任何和所有帮助将不胜感激。这是我的代码:

from pylab import *
from random import random
ioff()

r = range(10)
x = [3 + i + random() for i in r]
y = [50*i + random() for i in r]
x2 = [5 + i + random() for i in r]
y2 = [5*i + random() for i in r]

scatter(x,y, marker = 'o', hold = True, label = 'collected underwear',cmap=cm.Greys)
scatter(x2,y2, marker = 's', hold = True, label = 'Profit!',cmap=cm.Greys)
legend(loc='upper left')

show()

谢谢,

亚当

最佳答案

如果你只是想任意指定颜色,做

color="k"

为黑色,做

color="0.x"

对于灰度,x 可以是任何数字,只要 0.x 介于 0 和 1 之间。

但是如果你想让标记的颜色由另一个数组 z 决定,做

scatter(x,y,c=z, cmap=cm.Greys)

所以对于

from pylab import *
from random import random
r = range(10)
x = [3 + i + random() for i in r]
y = [50*i + random() for i in r]
x2 = [5 + i + random() for i in r]
y2 = [5*i + random() for i in r]
z2 = [i + random() for i in r]
scatter(x,y, c="0.1", marker = 'o', hold = True, label = 'collected underwear')
scatter(x2,y2, c=z2,marker = 's', hold = True, label = 'Profit!',cmap=cm.Greys)
legend(loc='upper left')
show()

你会拥有

enter image description here

关于Python:matplotlib - 黑白散点图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10628566/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com