I am new to python and to programming. I am trying to plot down an orientation map using python. I have a large number of points (about 1,200,000) on a plane and each of them belong to a cluster. Each cluster is supposed to be of different color. What I am doing currently is assigning a color to each cluster and drawing a filled circle at each point. I tried to do it in parts by creating plots for different segments and using blend to combine them. This is the code for the part: (sn is the total number of points, label is the cluster array of cluster number and xcoor and ycoor are the coordinates of the point)
pylab.xlim([0,250])
pylab.ylim([0,100])
plt.savefig("HK pickle.png")
for l in range (1, 20):
for j in range(int((float(sn)/80)*(l-1)), int((float(sn)/80)*(l))):
overlay = Image.open("HK pickle.png")
c = label[j] % 8
if c == 0:
circle1 = plt.Circle((float(xcoor[j]), float(ycoor[j])), 0.05, color = (0.5, 0, 0))
elif c == 1:
circle1 = plt.Circle((float(xcoor[j]), float(ycoor[j])), 0.05, color = (1, 0, 0))
elif c == 2:
circle1 = plt.Circle((float(xcoor[j]), float(ycoor[j])), 0.05, color = (0, 0.5, 0))
elif c == 3:
circle1 = plt.Circle((float(xcoor[j]), float(ycoor[j])), 0.05, color = (0, 1, 0))
elif c == 4:
circle1 = plt.Circle((float(xcoor[j]), float(ycoor[j])), 0.05, color = (0, 0, 0.5))
elif c == 5:
circle1 = plt.Circle((float(xcoor[j]), float(ycoor[j])), 0.05, color = (0, 0 ,1))
elif c == 6:
circle1 = plt.Circle((float(xcoor[j]), float(ycoor[j])), 0.05, color = (0.5, 0.5 ,0))
elif c == 7:
circle1 = plt.Circle((float(xcoor[j]), float(ycoor[j])), 0.05, color = (0.5, 0 ,0.5))
fig = plt.gcf()
fig.gca().add_artist(circle1)
del circle1
plt.savefig("HK pick.png")
del fig
back = Image.open("HK pick.png")
comp = Image.blend(back, overlay, 0.5)
comp.save("HK pickle.png", "PNG")
del comp
pylab.xlim([0,250])
pylab.ylim([0,100])
plt.savefig("HK plots.png")
However, this leads to the following error:
fig.gca().add_artist(circle1)
File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 1404, in add_artist
self.artists.append(a)
MemoryError
The error arises at l = 11. I kept checking the task manager in parallel and it still had almost 3GB free memory when the MemoryError showed up. Please help me with this.
I am new to this and still don't know if the information I've given is enough. please let me know if you need any more information