![](/img/trans.png)
[英]Axes fonts with text.usetex 'true' does not use set font
[英]How to set Helvetica font for axes labels (numbers) with matplotlib with usetex on?
我將 matplotlibrc 參數文件中的字體樣式設置為已安裝的 Helvetica(無襯線),並將 text.usetex 設置為“true”,但軸字體使用襯線字體。 我的 matplotlibrc 參數文件如下:
lines.linewidth : 1.0 # Line width (in points).
lines.linestyle : - # Line style.
lines.color : blue # Line color.
font.family : sans-serif
font.sans-serif : Helvetica, Arial, Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Avant Garde, sans-serif
text.color : black
text.usetex : true
axes.facecolor : FFFFFF # axes background color
axes.edgecolor : 000000 # axes edge color
axes.linewidth : 1.0 # edge linewidth
axes.grid : true # display grid or not
axes.titlesize : large # fontsize of the axes title
axes.labelsize : 9 # fontsize of the x any y labels
axes.labelweight : normal # weight of the x and y labels
axes.labelcolor : 000000
axes.axisbelow : true
axes.formatter.limits : -7, 7
axes.color_cycle : E41A1C, 377EB8, 4DAF4A, 984EA3, FF7F00, FFFF33, A65628, F781BF, 999999 # color cycle for plot lines
polaraxes.grid : true # display grid on polar axes
axes3d.grid : true # display grid on 3d axes
xtick.major.size : 4 # Major tick size (in points).
xtick.minor.size : 2 # Minor tick size (in points).
xtick.major.width : 1 # Major tick width (in points).
xtick.minor.width : 1 # Minor tick width (in points).
xtick.major.pad : 6 # Distance to major tick label (in points).
xtick.minor.pad : 6 # Distance to the minor tick label (in points).
xtick.color : 000000 # Tick label colors.
xtick.labelsize : 8 # Tick label font size (in points).
xtick.direction : in # Tick direction
ytick.major.size : 4 # Major tick size (in points).
ytick.minor.size : 2 # Minor tick size (in points).
ytick.major.width : 1 # Major tick width (in points).
ytick.minor.width : 1 # Minor tick width (in points).
ytick.major.pad : 6 # Distance to major tick label (in points).
ytick.minor.pad : 6 # Distance to the minor tick label (in points).
ytick.color : 000000 # Tick label colors.
ytick.labelsize : 8 # Tick label font size (in points).
ytick.direction : in # Tick direction
grid.color : 999999 # Grid color.
grid.linestyle : : # Grid line style.
grid.linewidth : 0.5 # Grid line width (in points).
grid.alpha : 1.0 # Grid line transparency.
legend.fancybox : true # if true, use a rounded box for the
legend.isaxes : true
legend.numpoints : 1 # the number of points in the legend line
legend.fontsize : 9
legend.borderpad : 0.5 # border whitespace in fontsize units
legend.markerscale : 1.0 # the relative size of legend markers vs. original
legend.labelspacing : 0.5 # the vertical space between the legend entries in fraction of fontsize
legend.handlelength : 2. # the length of the legend lines in fraction of fontsize
legend.handleheight : 0.7 # the height of the legend handle in fraction of fontsize
legend.handletextpad : 0.8 # the space between the legend line and legend text in fraction of fontsize
legend.borderaxespad : 0.5 # the border between the axes and legend edge in fraction of fontsize
legend.columnspacing : 2. # the border between the axes and legend edge in fraction of fontsize
legend.shadow : false
legend.frameon : true # whether or not to draw a frame around legend
legend.scatterpoints : 1 # number of scatter points
如何讓軸字體使用 Helvetica sans?
更新
我嘗試使用代碼:
plt.rcParams['font.family'] = 'Helvetica'
但這是我得到的錯誤:
/usr/lib/pymodules/python2.7/matplotlib/font_manager.py:1236: UserWarning: findfont: Font family ['Helvetica'] not found. Falling back to Bitstream Vera Sans
(prop.get_family(), self.defaultFamily[fontext]))
/usr/lib/pymodules/python2.7/matplotlib/font_manager.py:1246: UserWarning: findfont: Could not match :family=Bitstream Vera Sans:style=normal:variant=normal:weight=normal:stretch=normal:size=medium. Returning /usr/share/matplotlib/mpl-data/fonts/ttf/cmb10.ttf
UserWarning)
/usr/lib/pymodules/python2.7/matplotlib/font_manager.py:1246: UserWarning: findfont: Could not match :family=Bitstream Vera Sans:style=normal:variant=normal:weight=normal:stretch=normal:size=large. Returning /usr/share/matplotlib/mpl-data/fonts/ttf/cmb10.ttf
UserWarning)
您是否已將.ttf
文件添加到matplotlib
可以找到它們的位置? 操作系統的“已安裝”可能並不意味着matplotlib
“已安裝”。 查看這篇博文: http : //blog.olgabotvinnik.com/blog/2012/11/15/2012-11-15-how-to-set-helvetica-as-the-default-sans-serif-font-在/
將此添加到我的 matplotlibrc 文件中對我有用。
mathtext.fontset : custom
mathtext.it : Helvetica:italic
另外,我需要在我的/usr/local/anaconda3/lib/python3.7/site-packages/matplotlib/mpl-data/fonts/ttf
目錄中有 Helvetica-Oblique.ttf。 Olga Botvinnik 在她的回答和她的博客中有一些很好的說明。
請注意,您必須清除~/.matplotlib
下的緩存才能刷新它。
Matplotlib 表示不支持自定義字體集,這可能會在 Matplotlib 的未來更新中中斷。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.