簡體   English   中英

matplotlib乳膠輸出中希臘字母以粗體顯示

[英]Greek letters are printed bold in matplotlib latex output

我在matplotlib中使用乳膠輸出來為軸和圖例打印希臘符號。 (粗體)文本以常規字體粗細打印,但是某些特殊字符以粗體打印。 特別地,我的意思是微的畝,但也表示埃的(非希臘)符號。 但是,其他希臘符號如Omega也可以正常打印。 我舉了一個小例子來說明:

#!/usr/bin/python
# -*- coding: utf-8 -*-

import matplotlib as mpl
import matplotlib.pyplot as plt


mpl.rcParams['text.usetex'] = True
mpl.rcParams['text.latex.unicode'] = True

mpl.rcParams['font.family'] = 'serif'
mpl.rcParams['text.latex.preamble'] = [
    r"\usepackage{textgreek}",
    r"\usepackage{siunitx}"]


fig = plt.figure()

plt.plot([1, 2, 4], [0, 9, 7])
plt.xlabel(
    r"\si{\micro\metre} " +
    r"\si{\omega\metre} " +
    r"\si{\nano\metre} " +
    r"\si{\angstrom} " +
    r"\si{\micro\metre}\textmu")
plt.show()

fig.savefig('test.png')
fig.savefig('test.pdf')

我在實時輸出,矢量輸出和圖像輸出上遇到這個問題。 讓我感到困惑的是,我在工作中已過期的Ubuntu計算機上使用了一個月的腳本,但安裝了python 3.3。 現在,我嘗試在個人Arch機器上運行腳本,然后得到了問題。

您所安裝的字體似乎有問題,就我而言,我可以通過以下命令指定要使用的字體來解決此問題:

mpl.rcParams['font.serif'] = 'Times'

可在此處找到可用字體的列表: http : //matplotlib.org/users/customizing.html

很抱歉,正如Achim所說,我應該在這里發布我的解決方案。

沒什么特別的,只是我在Arch上安裝的字體有點搞砸了。 但是我也在文檔中使用的Palatino字體運行良好,因此我決定在Pyplot中也使用它。 這是我在Pyplot中的標准字體配置的樣子:

import matplotlib as mpl

mpl.rcParams['legend.fontsize'] ="large"
mpl.rcParams['axes.labelsize'] = "x-large"
mpl.rcParams['lines.linewidth'] = 2

mpl.rcParams['xtick.labelsize'] = "x-large"
mpl.rcParams['ytick.labelsize'] = "x-large"

mpl.rcParams['text.usetex'] = True
mpl.rcParams['text.latex.unicode'] = True
mpl.rcParams['text.latex.preamble'] = r"\usepackage{textcomp}" + \
    r"\usepackage{textgreek}" +\
    r"\usepackage{subscript}" +\
    r"\usepackage{siunitx}" +\
    r'\usepackage{amsmath}' +\
    r"\usepackage[osf]{mathpazo}"

mpl.rcParams['font.family'] = "Palatino"

簡短的一句話:我在mathpazo軟件包中使用舊樣式圖形。 這對於方程式和科學數字不是很有用。 如果您還想使用舊樣式,我真的建議您使用SIunitx軟件包(無論如何我還是建議這樣做),這樣可以避免osf。

如果您想避免使用osf以獲得獨立號碼,只需使用\\ num {123},或與單位\\ SI {123} {\\ celsius \\ per \\ square \\ hour}一起使用

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM