[英]Issues plotting huge scatter plot in python. Is there a better way to do this?
I built a huge ndarray object which is 2059263, 2 dimensions (one column for x-axis and another for y-axis).我构建了一个巨大的 ndarray object,它是 2059263,2 维(一列用于 x 轴,另一列用于 y 轴)。 I tried to plot a scatter plot using different color of points.
我尝试使用不同颜色的点 plot 分散 plot。 I created another same size list of arrays, which contain the information of the origin ndarray.
我创建了另一个相同大小的 arrays 列表,其中包含原始 ndarray 的信息。 So I tried to plot the scatter plot based on the category of information list combined with ndarray axis information using matplotlib.pyplot.
所以我尝试使用plot scatter plot 基于类别信息列表结合ndarray轴信息使用matplotlib.pyplot。 I tried to use if and elif condition loop, but the loop is infinite... Is there another way to deal with a huge axis array to plot the scatter plot...?
我尝试使用 if 和 elif 条件循环,但循环是无限的......有没有另一种方法来处理一个巨大的轴数组到 plot 分散 plot...? Or did I make a mistake in coding?
还是我在编码时犯了错误? Is there a faster way to do this?
有没有更快的方法来做到这一点? Probably the problem is that the origin axis array and information of each points are separated... attached my code below:
可能问题是原点轴数组和每个点的信息是分开的......在下面附上我的代码:
import re
import matplotlib.pyplot as plt
cdict = {0 : 'b', 1 : 'c', 2 : 'g', 3 : 'm', 4 : 'r', 5 : 'y',
6 : 'brown', 7 : 'gold', 8 : 'lightseagreen', 9 : 'indigo', 10 : 'maroon',
11 : 'cyan', 12 : 'olive', 13 : 'deeppink', 14 : 'sienna', 15 : 'crimson',
16 : 'peru', 17 : 'lime', 18 : 'navy', 19 : 'orange'}
count = 1
for i in range(len(mapping)):
if count != int(atr_list[i][1]):
print("wrong sequence")
print(count)
print(atr_list[i])
break
else:
attri = re.search('^\d{3}[0-9]', atr_list[i][0])
if int(attri.group()) < 2001:
colo = 0
elif int(attri.group()) > 2000 and int(attri.group()) < 2006:
colo = 1
elif int(attri.group()) > 2005 and int(attri.group()) < 2011:
colo = 2
elif int(attri.group()) > 2010 and int(attri.group()) < 2016:
colo = 3
elif int(attri.group()) > 2015:
colo = 4
plt.scatter(mapping[i, 0], mapping[i, 1], c=cdict[colo])
count += 1
plt.xlim(mapping[:, 0].min(), mapping[:, 0].max()) #
plt.ylim(mapping[:, 1].min(), mapping[:, 1].max()) #
plt.xlabel('t-SNE_x') #
plt.ylabel('t-SNE_y') #
plt.show() #
I figured out that that was my coding mistake.我发现那是我的编码错误。 I should have wrote plt.scatter() function not in the loop but outside of the loop.
我应该写 plt.scatter() function 不在循环中,而是在循环之外。 Since I plot the scatter plot million time, it was seemed like an infinite loop.
自从我 plot 分散 plot 万次之后,就好像死循环一样。 I was stupid.
我犯傻了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.