通常,打開 eps 檔案沒有問題,但是使用我正在處理的 Python 中的當前代碼,匯出的 eps 檔案在打開時正在加載但從未出現。我試過匯出與 png 相同的圖形,效果很好。此外,我嘗試將一個非常簡單的圖形匯出為 eps,并且打開時沒有任何缺陷。我已經包含了一些關于情節/圖形的相關代碼。任何幫助將非常感激。
#%% plot section
plt.close('all')
plt.figure()
plt.errorbar(r,omega,yerr=omega_err,fmt='mo')
plt.xlabel('xlabel')
plt.ylabel('ylabel')
plt.title('profile averaged from {} ms to {} ms \n shot {}'.format(tidsinterval[0],tidsinterval[1],skud_numre[0]),y=1.05)
plt.grid()
plt.axhline(y=2.45,color='Red')
plt.text(39,2.43,'txt block for horizontal line',backgroundcolor='white')
plt.axvline(x=37.5,color='Purple')
plt.text(37.5,1.2,'txt block for vertical line',ha='center',va="center",rotation='vertical',backgroundcolor='white')
plt.savefig('directory/plot.eps', format='eps')
plt.show()
變數 r, omega, omega_err 是小尺寸(可能是 6)浮點數的向量。
更新:我用來打開 eps 檔案的程式是 Evince,此外,可以在這里下載 eps 檔案https://filedropper.com/d/s/z7lxUCtANeox7tDMQ6dI6HZUpcTfHn。據我所知,通過社區指南通過 filedropper 共享檔案很好,但如果我錯了,請說出來。發現只要 plot 中不包含文本(例如 x-label、y-label、title 等)就可以打開檔案,因此問題必須與文本有關。
uj5u.com熱心網友回復:
簡短的回答是這是你的字體。/e 字形在 setcachedevice 上拋出一個錯誤(你的 PostScript 解釋器應該已經告訴你了)。
實際問題是字體程式(至少)粗心大意地使用了函式名。該程式包含以下內容:
/mpldict 11 dict def
mpldict begin
/d { bind def } bind def
這將創建一個名為 mpldict 的新字典,開始該字典(使其成為字典堆疊中的最頂層條目)并在該字典中定義一個名為 'd' 的函式
然后我們繼續字體定義,這里有很多樣板,但是每個字符形狀都由字體的 CharStrings 字典中的一個條目定義,我們將使用名為 'd' 的函式的定義來定義字體的 CharStrings 字典。
/d{1300 0 113 -29 1114 1556 sc
930 950 m
930 1556 l
ce} d
(2.60) == flush
/e{1260 0 113 -29 1151 1147 sc
1151 606 m
1151 516 l
305 516 l
313 389 351 293 419 226 c
488 160 583 127 705 127 c
776 127 844 136 910 153 c
977 170 1043 196 1108 231 c
1108 57 l
1042 29 974 8 905 -7 c
836 -22 765 -29 694 -29 c
515 -29 374 23 269 127 c
165 231 113 372 113 549 c
113 732 162 878 261 985 c
360 1093 494 1147 662 1147 c
813 1147 932 1098 1019 1001 c
1107 904 1151 773 1151 606 c
967 660 m
966 761 937 841 882 901 c
827 961 755 991 664 991 c
561 991 479 962 417 904 c
356 846 320 764 311 659 c
967 660 l
ce} d
請注意,這樣做是在當前字典中為名為 'd' 的函式創建一個新定義。這本身不是問題。我們現在有兩個名為 'd' 的函式;一個在當前字典中(字體的 CharStrings 字典),一個在 'mpldict' 中。
然后我們定義下一個字符:
/e{1260 0 113 -29 1151 1147 sc
1151 606 m
1151 516 l
305 516 l
313 389 351 293 419 226 c
488 160 583 127 705 127 c
776 127 844 136 910 153 c
977 170 1043 196 1108 231 c
1108 57 l
1042 29 974 8 905 -7 c
836 -22 765 -29 694 -29 c
515 -29 374 23 269 127 c
165 231 113 372 113 549 c
113 732 162 878 261 985 c
360 1093 494 1147 662 1147 c
813 1147 932 1098 1019 1001 c
1107 904 1151 773 1151 606 c
967 660 m
966 761 937 841 882 901 c
827 961 755 991 664 991 c
561 991 479 962 417 904 c
356 846 320 764 311 659 c
967 660 l
ce} d
現在,我們在定義字符形狀(對于名為“e”的字符)結束時做的最后一件事是呼叫名為“d”的函式。但是有兩種,我們稱其為哪一種?答案是我們在字典堆疊中向下查找每個字典以查看它是否有一個名為 'd' 的函式,然后我們使用我們找到的第一個函式。當前字典是字體的 CharStrings 字典,它有一個名為 'd'(定義 'd' 字符)的函式,所以我們稱之為。
然后該函式嘗試使用 setcachedevice。該運算子是不合法的,除非在執行字符描述時,我們沒有這樣做,所以它會拋出一個未定義的錯誤。
現在,您的 PostScript 解釋器應該會告訴您有錯誤(例如,Ghostscript 會這樣做)。因為有一個錯誤,解釋器停止并且不再繪制任何東西,這就是為什么你得到一個空白頁。
你能做些什么呢?好吧,您可以使用創建應用程式提出錯誤報告(顯然 Matplotlib 也創建了字體)。這不是定義字體的好方法!
除此之外,坦率地說,您唯一能做的就是搜索和替換檔案。如果您查找出現的情況ce} d并將其替換為ce}bind def它可能會起作用。這次。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/367652.html
標籤:Python matplotlib 每股收益
上一篇:盡管有R值,但看不到散點圖中的點
