2017-06-27 3 views
1

matplotlibでプロットを生成しようとしていて、 'stix'フォント(rcParams ['mathtext.fontset'] = 'stix')を使用してテキストから数学テキストへの滑らかなフォントサイズの遷移を持つ。しかし、私の数学記号のいくつかはイタリック(スカラー値)で、一部はイタリック(イタリック)になりたいおよびボールド(テンソル)。私はラテックスレンダリングを使用して解決策を検討したくないので、他のものがうんざりしてしまいます。あなたが最初のラベルは斜体であり、第二のラベルが太字でコードを実行した場合stplixフォントのMatplotlibでイタリックとボールドの両方のスタイルを作成する

from numpy import * 
from matplotlib.pyplot import * 

# Chaning font to stix 
rcParams['mathtext.fontset'] = 'stix' 

# Some data to constract this plotting example 
datax=[0,1,2] 
datay=[8,9,10] 
datay2=[8,15,10] 

fig, ay = subplots() 

ay.plot(datax, datay, color="0.", ls='-', label= r"$F_{\alpha}$") 
ay.plot(datax, datay2, color="0.", ls='-', label=r"$\mathbf{F_{\alpha}}$") 

# Now add the legend with some customizations. 
legend = ay.legend(loc='left', shadow=True) 

#frame = legend.get_frame() 
#frame.set_facecolor('0.90') 
xlabel(r"x label",fontsize=18) 
ylabel(r'y label', fontsize=18) 
grid() 

show() 

は、私はあなたの問題を描いている小さな例を提供します。 2番目のラベルをどのように太字と斜体にすることができますか?

Problem with math text to be Italic and bold

+0

私はそれが可能ではないと思います。本当のラテックス(すなわち、usetex = True)を使用する必要があるかもしれません。そして、この質問は役に立ちます:https://tex.stackexchange.com/questions/14395/bold-italic-vectors – ImportanceOfBeingErnest

答えて

0

もいくつかのより具体的なmathtext paramsが必要とされています

私も、軸ラベルに mathbfを使用
from numpy import * 
from matplotlib.pyplot import * 

# Changing font to stix; setting specialized math font properties as directly as possible 
rcParams['mathtext.fontset'] = 'custom' 
rcParams['mathtext.it'] = 'STIXGeneral:italic' 
rcParams['mathtext.bf'] = 'STIXGeneral:italic:bold' 

# Some data to construct this plotting example 
datax=[0,1,2] 
datay=[8,9,10] 
datay2=[8,15,10] 

fig, ay = subplots() 

ay.plot(datax, datay, color="0.", ls='-', label= r"$\mathit{F_{\alpha}}$") 
ay.plot(datax, datay2, color="0.", ls='-', label=r"$\mathbf{F_{\alpha}}$") 

# Now add the legend with some customizations. 
legend = ay.legend(loc='left', shadow=True) 

# Using the specialized math font again 
xlabel(r"$\mathbf{x}$ label",fontsize=18) 
ylabel(r'y label', fontsize=18) 
grid() 

show() 

enter image description here

注意。おそらく残りのラベルをSTIXフォントに変更するでしょう。これは非イタリックで非大胆な場合を定義できます。「カスタムフォント」のdocsを参照してください。

+0

ありがとうございます!それが私の必要でした! – Alex

+0

完全な答えであれば、それをチェックして、質問/回答を探している他の人がどのような状態であるかを知るようにしてください。 また、あなたの例がシンプルで明確で、_complete_であったため、簡単に答えることができました。 – cphlewis

-1

だから、matplotlibのは、LaTeXの構文を使用しているので、私の最高の推測では、どのように斜体や太字を取得するためにあなたがLaTeXの構文を使用することができるということです、それは希望あなたのケースで

\textbf{\textit{text}} 

そうです

ay.plot(datax, datay2, color="0.", ls='-', label= r"$\mathbf{ \textit{F_{\alpha}} }$") 
+0

答えはうまくいかない。 – ImportanceOfBeingErnest

関連する問題