首页 > 解决方案 > Matplotlib 用线连接散点图

问题描述

我读了问题 Matplotlib connect scatterplot points with line - Python但它对我不起作用......

我尝试使用plt.scatter(x, y)and 之后plt.show(),但我看到的只是一组彼此分开的点。

像那样:

我认为,这个问题在于我使用循环来生成绘图上的每个点,然后在循环之后使用plt.show().

我所有的代码都是这样的:

x = 0
y = 0
def eye_gaze1(a,b):
    global x,y
    image_plot1 = plt.imshow(image1)
    for i in range(len(a)):
        if stimulus_name[x+y+1] == '5_01.jpg' and a[x+y+1] != '-':
            plt.scatter([a[x+y+1]], [b[x+y+1]]) #here I putting new point on the image_plot1 and this process repeats (something like 1000 times) before in my massive of data cycle will find '-' symbol
            x += 1
        else:
            x += 1
            break

    plt.show() #final image
    y += x
    x = 0

j = 0    
while j < 15: #just repeat this function for another cells in data-massive 
    eye_gaze1(col_values_X_right,col_values_Y_right) 
    j += 1

所以,问题是,我怎样才能连接点?


如果我尝试使用 JohanC 的评论,我会看到这个错误:TypeError: ufunc 'sqrt' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

x = 0
y = 0
def eye_gaze1(a,b):
    global x,y
    image_plot1 = plt.imshow(image1)
    for i in range(len(a)):
        if stimulus_name[x+y+1] == '5_01.jpg' and a[x+y+1] != '-':
            X_coordinates = list().append(a[x+y+1])
            Y_coordinates = list().append(b[x+y+1])

            x += 1
        else:
            x += 1
            break
    plt.scatter(X_coordinates, Y_coordinates, '-o')    
    plt.show()
    y += x
    x = 0

j = 0    
while j < 15:
    eye_gaze1(col_values_X_right,col_values_Y_right)
    print(x)
    print(y)
    j += 1

标签: pythonmatplotlib

解决方案


推荐阅读