I have created a plot in matplot lib and I wish to add an inset to that plot. The data I wish to plot is kept inside of a dictionary that I use in other figures. I'm finding this data inside a loop which I then run this loop again for the subplot. Here is the relevant segment:
leg = []
colors=['red','blue']
count = 0
for key in Xpr: #Xpr holds my data
#skipping over what I don't want to plot
if not key[0] == '5': continue
if key[1] == '0': continue
if key[1] == 'a': continue
leg.append(key)
x = Xpr[key]
y = Ypr[key] #Ypr holds the Y axis and is created when Xpr is created
plt.scatter(x,y,color=colors[count],marker='.')
count += 1
plt.xlabel(r'$z/\mu$')
plt.ylabel(r'$\rho(z)$')
plt.legend(leg)
plt.xlim(0,10)
#Now I wish to create the inset
a=plt.axes([0.7,0.7,0.8,0.8])
count = 0
for key in Xpr:
break
if not key[0] == '5': continue
if key[1] == '0': continue
if key[1] == 'a': continue
leg.append(key)
x = Xpr[key]
y = Ypr[key]
a.plot(x,y,color=colors[count])
count += 1
plt.savefig('ion density 5per Un.pdf',format='pdf')
plt.cla()
The strange thing is that when I tried to move the inset position, I still get the previous insets (those from the previous run of the code). I even tried to comment out the a=axes([])
line without any apparent. I attach en example file. Why is it acting in that way?