⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fonts_demo.py

📁 非原创。很好的python例子
💻 PY
字号:
#!/usr/bin/env python"""Show how to set custom font properties.For interactive users, you can also use kwargs to the text command,which requires less typing.  See exampes/fonts_demo_kw.py"""from matplotlib.font_manager import fontManager, FontPropertiesfrom pylab import *subplot(111, axisbg='w')font0 = FontProperties()alignment = {'horizontalalignment':'center', 'verticalalignment':'center'}###  Show family optionsfamily = ['serif', 'sans-serif', 'cursive', 'fantasy', 'monospace']font1 = font0.copy()font1.set_size('large')t = text(-0.8, 0.9, 'family', fontproperties=font1,         **alignment)yp = [0.7, 0.5, 0.3, 0.1, -0.1, -0.3, -0.5]for k in range(5):    font = font0.copy()    font.set_family(family[k])    if k == 2:        font.set_name('Script MT')    t = text(-0.8, yp[k], family[k], fontproperties=font,             **alignment)###  Show style optionsstyle  = ['normal', 'italic', 'oblique']t = text(-0.4, 0.9, 'style', fontproperties=font1,         **alignment)for k in range(3):    font = font0.copy()    font.set_family('sans-serif')    font.set_style(style[k])    t = text(-0.4, yp[k], style[k], fontproperties=font,             **alignment)###  Show variant optionsvariant= ['normal', 'small-caps']t = text(0.0, 0.9, 'variant', fontproperties=font1,         **alignment)for k in range(1):    font = font0.copy()    font.set_family('serif')    font.set_variant(variant[k])    t = text( 0.0, yp[k], variant[k], fontproperties=font,             **alignment)###  Show weight optionsweight = ['light', 'normal', 'medium', 'semibold', 'bold', 'heavy', 'black']t = text( 0.4, 0.9, 'weight', fontproperties=font1,         **alignment)for k in range(7):    font = font0.copy()    font.set_weight(weight[k])    t = text( 0.4, yp[k], weight[k], fontproperties=font,             **alignment)###  Show size optionssize  = ['xx-small', 'x-small', 'small', 'medium', 'large',         'x-large', 'xx-large']t = text( 0.8, 0.9, 'size', fontproperties=font1,         **alignment)for k in range(7):    font = font0.copy()    font.set_size(size[k])    t = text( 0.8, yp[k], size[k], fontproperties=font,             **alignment)###  Show bold italicfont = font0.copy()font.set_style('italic')font.set_weight('bold')font.set_size('x-small')t = text(0, 0.1, 'bold italic', fontproperties=font,         **alignment)font = font0.copy()font.set_style('italic')font.set_weight('bold')font.set_size('medium')t = text(0, 0.2, 'bold italic', fontproperties=font,         **alignment)font = font0.copy()font.set_style('italic')font.set_weight('bold')font.set_size('x-large')t = text(0, 0.3, 'bold italic', fontproperties=font,         **alignment)axis([-1,1,0,1])#savefig('fonts_demo')show()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -