figlegend_demo
图形图例演示不是在每个轴上绘制图例,而是可以绘制图形的所有子轴上的所有艺术家的图例。 12345678910111213141516171819import numpy as npimport matplotlib.pyplot as pltfig, axs = plt.subplots(1, 2)x = np.arange(0.0, 2.0, 0.02)y1 = np.sin(2 * np.pi * x)y2 = np.exp(-x)l1, l2 = axs[0].plot(x, y1, 'rs-', x, y2, 'go')y3 = np.sin(4 * np.pi * x)y4 = np.exp(-2 * x)l3, l4 = axs[1].plot(x, y3, 'yd-', x, y4, 'k^')fig.legend((l1, l2), ('Line 1', 'Line 2'), 'upper left')fig.legend(...
font_family_rc_sgskip
配置字体系列你可以明确地设置为给定字体样式拾取的字体系列(例如,‘serif’、‘sans-serif’或‘monSpace’)。 在下面的示例中,我们只允许一个字体系列(Tahoma)用于sans-serif字体样式。你是font.family rc param的默认系列,例如: 1rcParams['font.family'] = 'sans-serif' 并为font.family设置一个字体样式列表,以尝试按顺序查找: 12rcParams['font.sans-serif'] = ['Tahoma', 'DejaVu Sans', 'Lucida Grande', 'Verdana'] 12345678910from matplotlib import rcParamsrcParams['font.family'] = 'sans-seri...
font_file
在Matplotlib中使用TTF字体文件虽然为字体实例显式指向单个ttf文件通常不是一个好主意,但您可以使用 font_manager.FontProperties fname 参数执行此操作。 在这里,我们使用Matplotlib附带的计算机现代罗马字体(cmr10)。 有关更灵活的解决方案,请参见配置字体系列和字体演示(面向对象的样式)。 12345678910111213import osfrom matplotlib import font_manager as fm, rcParamsimport matplotlib.pyplot as pltfig, ax = plt.subplots()fpath = os.path.join(rcParams["datapath"], "fonts/ttf/cmr10.ttf")prop = fm.FontProperties(fname=fpath)fname = os.path.split(fpath)[1]ax.set_title('This is a special f...
font_table_ttf_sgskip
TTF字体表Matplotlib支持FreeType字体。下面是一个使用‘table’命令构建字体表的小示例,该表按字符代码显示字形。 用法python font_table_ttf.py somefile.ttf 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253import sysimport osimport matplotlibfrom matplotlib.ft2font import FT2Fontfrom matplotlib.font_manager import FontPropertiesimport matplotlib.pyplot as plt# the font table gridlabelc = ['0', '1', '2', '3', '4', '5', '6', &...
fonts_demo
字体演示(面向对象的风格)使用setter设置字体属性。 请参见字体演示(Kwargs),以使用kwargs实现相同的效果。 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106from matplotlib.font_manager import FontPropertiesimport matplotlib.pyplot as pltplt.subplot(111, facecolor='w')font0 = FontProperties()alignment = {'horizontalalignment': 'center', '...
fonts_demo_kw
字体演示(kwargs)使用kwargs设置字体属性。 请参阅字体演示(面向对象样式),以使用setter实现相同的效果。 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374import matplotlib.pyplot as pltplt.subplot(111, facecolor='w')alignment = {'horizontalalignment': 'center', 'verticalalignment': 'baseline'}# Show family optionsfamilies = ['serif', 'sans-serif', 'cursive'...
legend_demo
图例(Legend)演示在Matplotlib中绘制图例。 在Matplotlib中有很多方法可以创建和自定义图例。 下面我们将展示一些如何操作的示例。 首先,我们将展示如何为特定线条制作图例。 1234567891011121314151617181920212223import matplotlib.pyplot as pltimport matplotlib.collections as mcolfrom matplotlib.legend_handler import HandlerLineCollection, HandlerTuplefrom matplotlib.lines import Line2Dimport numpy as npt1 = np.arange(0.0, 2.0, 0.1)t2 = np.arange(0.0, 2.0, 0.01)fig, ax = plt.subplots()# note that plot returns a list of lines. The "l1, = plot" usage# extracts...
line_with_text
艺术家中的艺术家重写基本方法,以便一个艺术家对象可以包含另一个艺术家对象。在这种情况下,该行包含一个文本实例来为其添加标签。 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556import numpy as npimport matplotlib.pyplot as pltimport matplotlib.lines as linesimport matplotlib.transforms as mtransformsimport matplotlib.text as mtextclass MyLine(lines.Line2D): def __init__(self, *args, **kwargs): # we'll update the position when the line data is set self.text = mtext.Text(0, 0, '...
legend
使用预定义标签的图例使用图定义图例标签。 1234567891011121314151617181920import numpy as npimport matplotlib.pyplot as plt# Make some fake data.a = b = np.arange(0, 3, .02)c = np.exp(a)d = c[::-1]# Create plots with pre-defined labels.fig, ax = plt.subplots()ax.plot(a, c, 'k--', label='Model length')ax.plot(a, d, 'k:', label='Data length')ax.plot(a, c + d, 'k', label='Total message length')legend = ax.legend(loc='upper center', shadow=True, fon...
mathtext_asarray
数学文本图像作为numpy数组从LaTeX字符串制作图像。 1234567891011121314151617181920import matplotlib.mathtext as mathtextimport matplotlib.pyplot as pltimport matplotlibmatplotlib.rc('image', origin='upper')parser = mathtext.MathTextParser("Bitmap")parser.to_png('test2.png', r'$\left[\left\lfloor\frac{5}{\frac{\left(3\right)}{4}} ' r'y\right)\right]$', color='green', fonts...














