python - 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
解决方案
推荐阅读
- python - Django Admin 将我的外键显示为中间模型作为文本输入
- c++ - VS2013,Visual C++ 命令行应用程序:为什么我收到错误 C1069:仅在发布版本时无法读取编译器命令行?
- java - 将对象作为引用传递
- r - 如何在 r highcharter 中的栏旁边显示标签?
- python - Python:通过图像的错误迭代
- linq - LINQ Cast 抛出从十进制到双精度的异常
- ruby - 如何在 Ruby 中组织 Procs?
- sql - 选择具有相同 ID 的行,折叠具有空/非空值的行
- restsharp - 网络凭据未在 RestSharp conole 应用程序中通过
- r - 如何在 ggplot 中使用 facet_wrap 绘制 5 点线图和 1 点条形图