最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Struggling with plt.scatter() - Stack Overflow

programmeradmin1浏览0评论

I'm trying to do a logistic map using the code below, but I'm struggling with making a scatter plot because I keep getting this error: "scatter() missing 1 required positional argument: 'y'". I understand I'm missing another 'y' but I don't know what I'm supposed to add.

allys = []

for r in np.arange(0.001, 4, 0.001):
    y = np.random.rand()
    for t in range(1000):
        y = r * y * (1 - y)
        if t > 959:
            allys.append(y)
        
plt.scatter(allys, color = 'black', s = 1) #<--error from here
plt.xticks(np.arange(0, 4, 0.5))
plt.show()

TypeError: scatter() missing 1 required positional argument: 'y'"

I'm trying to do a logistic map using the code below, but I'm struggling with making a scatter plot because I keep getting this error: "scatter() missing 1 required positional argument: 'y'". I understand I'm missing another 'y' but I don't know what I'm supposed to add.

allys = []

for r in np.arange(0.001, 4, 0.001):
    y = np.random.rand()
    for t in range(1000):
        y = r * y * (1 - y)
        if t > 959:
            allys.append(y)
        
plt.scatter(allys, color = 'black', s = 1) #<--error from here
plt.xticks(np.arange(0, 4, 0.5))
plt.show()

TypeError: scatter() missing 1 required positional argument: 'y'"
Share Improve this question asked Mar 12 at 20:50 magicgeniemagicgenie 1
Add a comment  | 

1 Answer 1

Reset to default 0

You are only passing in allys. You need to also define a second array for the x values and pass that into plt.scatter as it requires x and y coordinates to work.

E.g.

allys = []
allxs = []

for r in np.arange(0.001, 4, 0.001):
    y = np.random.rand()
    for t in range(1000):
        y = r * y * (1 - y)
        if t > 959:
            allys.append(y)
            allxs .append(r) 

plt.scatter(allxs , allys, color='black', s=1)  
发布评论

评论列表(0)

  1. 暂无评论