2017-08-25 32 views
1

だから、私はstackoverflowで見つけられるすべてのものを試しました。私はちょうど神の気まぐれなフォントを変更することはできません!matplotlibのフォントを変更する

this questionで提案されているようにしよう:

>>> (executing file "<tmp 1>") 
Note on using QApplication.exec_(): 
The GUI event loop is already running in the pyzo kernel, and exec_() 
does not block. In most cases your app should run fine without the need 
for modifications. For clarity, this is what the pyzo kernel does: 
- Prevent deletion of objects in the local scope of functions leading to exec_() 
- Prevent system exit right after the exec_() call 
/home/antoine/miniconda3/lib/python3.6/site-packages/matplotlib/font_manager.py:1297: UserWarning: findfont: Font family ['Times New Roman'] not found. Falling back to DejaVu Sans 
    (prop.get_family(), self.defaultFamily[fontext])) 

>>> 

import matplotlib.pyplot as plt 
csfont = {'fontname':'Times New Roman'} 
x = [1,2,3] 
y = x 

plt.plot(x,y) 

plt.title('Please be Times >__<',**csfont) 

plt.show() 

が私にこのエラーログを提供します。ここ

は、私がこれまで試したものの非網羅的なリストが来ます This answerはどちらも私を助けませんでした:

import matplotlib.pyplot as plt 
plt.rcParams["font.family"] = "Times New Roman" 
x = [1,2,3] 
y = x 

plt.plot(x,y) 

plt.title('Please be Times >__<',**csfont) 

plt.show() 

エラーは表示されません。しかし、これは最初の試みでのTimes New Romanは確かに私はあるべきフォントであることを示していることを示唆しているものをthis answerやって、そのエラーログを与えることも私にはビット奇妙だタイムズ...

Still not Times

ではありません使用できる:

>>> set([f.name for f in matplotlib.font_manager.fontManager.afmlist]) 
{'Courier', 'Times', 'URW Bookman L', 'Nimbus Mono L', 'ITC Bookman', 'ZapfDingbats', 'Century Schoolbook L', 'New Century Schoolbook', 'Helvetica', 'Standard Symbols L', 'Utopia', 'Palatino', 'URW Gothic L', 'Courier 10 Pitch', 'Symbol', 'Computer Modern', 'Bitstream Charter', 'ITC Avant Garde Gothic', 'Nimbus Roman No9 L', 'ITC Zapf Chancery', 'ITC Zapf Dingbats', 'URW Chancery L', 'Nimbus Sans L', 'Dingbats', 'URW Palladio L'} 

だから私は何を試すことができますか?使用可能なフォントを参照するために

+0

は、あなたが他のフォントで試したことがありますか?とにかく、あなたの最後のスニペットは、あなたが使うフォント名が '' Times New Roman''の代わりに '' Times''であるかもしれないことを示唆しているようです。 – jdehesa

+0

私は両方を試しました、 'Times-Roman'でも、それはまだ動作しませんでした.. –

答えて

1

、あなたがthis methodを使用する必要があります。

import matplotlib.font_manager 
flist = matplotlib.font_manager.get_fontconfig_fonts() 
names = [matplotlib.font_manager.FontProperties(fname=fname).get_name() for fname in flist] 
print names 

次に「のTimes New Roman」がであるかどうかを参照してください。

if "Times New Roman" in names: 
    print "Yes" 
else: 
    print "font not available" 

使用できない場合は使用できません。そうであれば、次のように動作します。

import matplotlib.pyplot as plt 
plt.rcParams["font.family"] = "Times New Roman" 

plt.plot([1,2,3]) 

plt.title('Please be Times New Roman') 

plt.show() 

複数のフォントを指定できます。実際に利用可能な最初のものが選択されます。リストの最後に"serif"を追加すると、少なくとも他のものが存在しない場合は必ずserifフォントにフォールバックします。

plt.rcParams["font.family"] = "Gulasch", "Times", "Times New Roman", "serif" 
+0

'Times new Roman'はそこにはないようです。 [この質問](https://stackoverflow.com/a/20276525/8427606)で提案されているように強制的に追加する必要がありますか、それとも簡単な方法がありますか? –

+0

あなたがリンクしている質問は良いです。実際にTimes New Romanフォントファイルがどこかに存在するかどうかをチェックする必要があります(ディレクトリに追加しない場合はフォントキャッシュを空にします)。仕事ができました。 – ImportanceOfBeingErnest

+0

さて、時代に非常によく似たSTIXフォントがあるようです。私はそれが既に含まれているものを使用するだけで安全だと思います! –

0

私は同じ警告と同じ問題たい:私は今、私はTimes New Romanを使用することができますthis.

を見つけるまで、私は無駄にスタックオーバーフローの記事をたくさん読ん

UserWarning: findfont: Font family ['Times New Roman'] not found. Falling back to DejaVu Sans

をin matplotlib

私の場合は、sudo

sudo cp /usr/share/fonts/truetype/msttcorefonts/Times_New_Roman* /usr/local/lib/python2.7/dist-packages/matplotlib/mpl-data/fonts/ttf

私は見ていただきたいもう一つは、ポストの最後の提案だった、すなわち:私は代わりに、これを行うためにいただきたい仮想環境を使用していないイム以来、D、

注:フォントが描画されていない場合はmatplotlibのは、そのフォントキャッシュをリフレッシュする必要があるため、それは、(ケビンさんのコメントを参照してください):

import matplotlib

matplotlib.font_manager._rebuild()

それ私のために働かなかった。代わりに私が使用:

import matplotlib.font_manager as fm

fm._rebuild()

関連する問題