我已經在matplot庫中創建了一個圖並且我希望爲該圖添加一個插圖。我想繪製的數據保存在我用於其他數字的字典中。我在一個循環內找到這個數據,然後我再次爲這個子區域運行這個循環。下面是相關段:在matplot庫中創建插圖
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()
奇怪的是,當我試圖移動插畫位置上,我仍然得到以前的插圖(那些從以前的代碼的運行)。我甚至試圖評論出a=axes([])
線沒有任何明顯的。我附上了示例文件。爲什麼它以這種方式行事?
您是否在某些交互式環境中運行此代碼? – tacaswell
我通過Emacs運行它。當我在終端中直接使用它時,有更好的結果 – Yotam