散点图为什么没有绘制所有点?

huangapple go评论100阅读模式
英文:

Why does scatter plot not plot all the points

问题

我有一组点:

a = [0.61561561,  1.24828584,  0.15447159,  0.94014534,  1.24828584,
        1.24828584,  0.92375611,  0.92375611,  0.47900132,  0.52270525,
        0.61561561,  0.47900132,  0.47900132,  0.3984379 ,  0.3984379 ,
       -0.75793657, -0.2629685 ,  0.36970173,  0.36970173, -0.75793657,
       -0.66502621, -0.20388219, -0.06270612,  0.94014534,  0.61561561,
       -0.66502621, -0.86528859, -0.86528859, -0.86528859, -0.54075886,
       -0.12331877,  0.045172  , -0.20388219, -0.91880682,  0.15447159,
       -0.06270612,  0.47900132,  0.47900132,  0.92375611, -1.0824663 ,
       -0.86528859, -0.40414457,  0.01329552,  0.01329552, -0.86528859,
        0.01329552, -0.86528859,  1.24828584, -0.91880682, -0.12331877,
        0.83084575,  0.3984379 ,  0.3984379 ,  0.94014534, -0.20388219,
        0.83084575, -0.29679254, -0.86528859, -0.75793657, -0.12331877,
        0.36970173,  0.12064755, -0.86528859, -1.0824663 , -0.4478485 ,
       -0.86528859,  0.06156123,  0.94014534, -1.0824663 , -0.20388219,
       -1.0824663 ,  0.01329552,  0.01329552, -0.4478485 ,  0.01329552]

b = [-5.02614441e-01,  2.52924699e-01, -2.35966674e-02, -1.25032819e-04,
        2.52924699e-01,  2.52924699e-01, -2.49564710e-01, -2.49564710e-01,
        4.78892741e-01,  5.21987286e-01, -5.02614441e-01,  4.78892741e-01,
        4.78892741e-01, -8.80642424e-01, -8.80642424e-01,  4.28537473e-01,
        4.98515651e+00,  1.25405479e+00,  1.25405479e+00,  4.28537473e-01,
       -5.96064254e-01, -1.07508203e+00, -4.01624650e-01, -1.25032819e-04,
       -5.02614441e-01, -5.96064254e-01,  3.04076047e-01,  3.04076047e-01,
        3.04076047e-01,  8.06565455e-01,  2.84453137e-01,  7.51565383e-01,
       -1.07508203e+00,  3.30514875e-01, -2.35966674e-02, -4.01624650e-01,
        4.78892741e-01,  4.78892741e-01, -2.49564710e-01, -7.39519357e-02,
        3.04076047e-01, -1.74941727e-01, -6.97054046e-01, -6.97054046e-01,
        3.04076047e-01, -6.97054046e-01,  3.04076047e-01,  2.52924699e-01,
        3.30514875e-01,  2.84453137e-01,  7.75037017e-01, -8.80642424e-01,
       -8.80642424e-01, -1.25032819e-04, -1.07508203e+00,  7.75037017e-01,
       -5.04803011e-02,  3.04076047e-01,  4.28537473e-01,  2.84453137e-01,
        1.25405479e+00, -5.72592620e-01,  3.04076047e-01, -7.39519357e-02,
       -2.18036272e-01,  3.04076047e-01,  1.00100506e+00, -1.25032819e-04,
       -7.39519357e-02, -1.07508203e+00, -7.39519357e-02, -6.97054046e-01,
       -6.97054046e-01, -2.18036272e-01, -6.97054046e-01]

我试图散点绘制它:

plt.scatter(a, b, alpha=0.7)

我想知道为什么它只绘制了大约 25-30 个点,而不是全部的 75 个点。我也不理解为什么有些点的颜色不同。

英文:

I have a set of points:

a = [0.61561561,  1.24828584,  0.15447159,  0.94014534,  1.24828584,
1.24828584,  0.92375611,  0.92375611,  0.47900132,  0.52270525,
0.61561561,  0.47900132,  0.47900132,  0.3984379 ,  0.3984379 ,
-0.75793657, -0.2629685 ,  0.36970173,  0.36970173, -0.75793657,
-0.66502621, -0.20388219, -0.06270612,  0.94014534,  0.61561561,
-0.66502621, -0.86528859, -0.86528859, -0.86528859, -0.54075886,
-0.12331877,  0.045172  , -0.20388219, -0.91880682,  0.15447159,
-0.06270612,  0.47900132,  0.47900132,  0.92375611, -1.0824663 ,
-0.86528859, -0.40414457,  0.01329552,  0.01329552, -0.86528859,
0.01329552, -0.86528859,  1.24828584, -0.91880682, -0.12331877,
0.83084575,  0.3984379 ,  0.3984379 ,  0.94014534, -0.20388219,
0.83084575, -0.29679254, -0.86528859, -0.75793657, -0.12331877,
0.36970173,  0.12064755, -0.86528859, -1.0824663 , -0.4478485 ,
-0.86528859,  0.06156123,  0.94014534, -1.0824663 , -0.20388219,
-1.0824663 ,  0.01329552,  0.01329552, -0.4478485 ,  0.01329552]
b = [-5.02614441e-01,  2.52924699e-01, -2.35966674e-02, -1.25032819e-04,
2.52924699e-01,  2.52924699e-01, -2.49564710e-01, -2.49564710e-01,
4.78892741e-01,  5.21987286e-01, -5.02614441e-01,  4.78892741e-01,
4.78892741e-01, -8.80642424e-01, -8.80642424e-01,  4.28537473e-01,
4.98515651e-01,  1.25405479e+00,  1.25405479e+00,  4.28537473e-01,
-5.96064254e-01, -1.07508203e+00, -4.01624650e-01, -1.25032819e-04,
-5.02614441e-01, -5.96064254e-01,  3.04076047e-01,  3.04076047e-01,
3.04076047e-01,  8.06565455e-01,  2.84453137e-01,  7.51565383e-01,
-1.07508203e+00,  3.30514875e-01, -2.35966674e-02, -4.01624650e-01,
4.78892741e-01,  4.78892741e-01, -2.49564710e-01, -7.39519357e-02,
3.04076047e-01, -1.74941727e-01, -6.97054046e-01, -6.97054046e-01,
3.04076047e-01, -6.97054046e-01,  3.04076047e-01,  2.52924699e-01,
3.30514875e-01,  2.84453137e-01,  7.75037017e-01, -8.80642424e-01,
-8.80642424e-01, -1.25032819e-04, -1.07508203e+00,  7.75037017e-01,
-5.04803011e-02,  3.04076047e-01,  4.28537473e-01,  2.84453137e-01,
1.25405479e+00, -5.72592620e-01,  3.04076047e-01, -7.39519357e-02,
-2.18036272e-01,  3.04076047e-01,  1.00100506e+00, -1.25032819e-04,
-7.39519357e-02, -1.07508203e+00, -7.39519357e-02, -6.97054046e-01,
-6.97054046e-01, -2.18036272e-01, -6.97054046e-01]

which I try to scatter plot:

plt.scatter(a, b, alpha=0.7)

And was wondering why it only plots around 25-30 points among the 75. I also don't understand why some points have different shades.

答案1

得分: 3

你一遍又一遍地绘制相同的数值。颜色变化是因为你使用了alpha=0.7,所以较暗的点是更多点叠加在一起的地方。

zipped = list(zip(a, b))
print(len(zipped))       # 75
print(len(set(zipped)))  # 27

集合创建一个没有重复的集合,所以在这种情况下,你只有27对唯一的值。

英文:

You're plotting the same values over and over again. The colour changes because you're using alpha=0.7, so the darker points are where more points have been plotted on top of each other.

zipped = list(zip(a, b))
print(len(zipped))       # 75
print(len(set(zipped)))  # 27

Set creates a collection without duplicates, so in this case you only have 27 unique pairs.

huangapple
  • 本文由 发表于 2023年3月15日 18:52:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/75743701.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定