gpt4 book ai didi

python - 绘制散点图时的问题

转载 作者:太空宇宙 更新时间:2023-11-04 09:17:00 24 4
gpt4 key购买 nike

我正在使用 matplotlib.pyplot.scatter 绘制一些简单的散点图。但是,出现了错误,我找不到解决方案。下面是绘制散点图的代码:

 # xActA, yActA, xActQ, yActQ are all lists with same dimensions.
ax1 = scatter(xActA, yActA, color = 'blue',s = 20, label = 'Answers', linestyle = 'o')
ax2 = scatter(xActQ, yActQ, color = 'black', s = 20, label = 'Questions', linestyle = 'o')
ax1.set_label('Answers')
ax2.set_label('Questions')
xscale('log')
yscale('log')
title('User activity')
xlabel('Number of posts')
ylabel('Number of users')
legend()
f1.show()
f1.savefig('figure7_test.png')

并且没有错误,但绘图不包含任何点。

enter image description here

数据如下:

xActA = [0, 1, 2, 3, 4, 5, 6, 129, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 147, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
35, 36, 39, 40, 7, 45, 46, 49, 50, 52, 53, 183, 59, 63, 65, 69,
70, 72, 73, 55, 77, 78, 84, 85, 43, 215, 88, 100, 94, 131, 167,
19, 375, 122, 125, 149]

len(xActA) = 70

yActA = [1212, 822, 194, 94, 61, 44, 24, 1, 26, 20, 11, 16, 10, 8, 5, 8,
5, 5, 3, 1, 4, 4, 5, 3, 2, 3, 4, 3, 1, 2, 2, 3, 2, 1, 2, 2, 2, 2,
31, 2, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1]

len(yActA) = 70

xActQ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 29, 36, 40, 45, 48, 50, 55, 67, 124]
len(xActQ) = 34

yActQ [204, 242, 150, 50, 49, 27, 5, 9, 4, 2, 6, 3, 2, 8, 4, 5, 1, 3, 3, 1, 3, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
len(yActQ) = 24

第二个错误是使用另一个数据集引发的。我正在检查数据...对于之前不清楚的描述很抱歉。

最佳答案

问题出在 linestyle='o' 上。 'o' 指令是一个marker,而不是一个linestyle,因此将linestyle 替换为marker 在你的前两行代码中。

您可以看到scatter 的完整标记列表here .

关于python - 绘制散点图时的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8105926/

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