mathtext_demo
数学文本演示使用Matplotlib的内部LaTeX解析器和布局引擎。 有关真正的LaTeX渲染,请参阅text.usetex选项。 1234567891011121314151617import matplotlib.pyplot as pltfig, ax = plt.subplots()ax.plot([1, 2, 3], 'r', label=r'$\sqrt{x^2}$')ax.legend()ax.set_xlabel(r'$\Delta_i^j$', fontsize=20)ax.set_ylabel(r'$\Delta_{i+1}^j$', fontsize=20)ax.set_title(r'$\Delta_i^j \hspace{0.4} \mathrm{versus} \hspace{0.4} ' r'\Delta_{...
rainbow_text
彩虹文本该示例演示如何将多个文本对象串在一起。 过去在2012年2月的matplotlib-users列表中,GökhanSever提出以下问题: matplotlib中有一种可以部分指定字符串的颜色的方法吗? 例子: 1plt.ylabel("Today is cloudy.") How can I show "today" as red, "is" as green and "cloudy." as blue? 感谢。 Paul Ivanov 的回答: 1234567891011121314151617181920212223242526272829303132333435363738394041424344import matplotlib.pyplot as pltfrom matplotlib import transformsdef rainbow_text(x, y, strings, colors, ax=None, **kw): """ ...
multiline
多线(Multiline) 123456789101112131415161718192021222324252627282930313233343536373839import matplotlib.pyplot as pltimport numpy as npplt.figure(figsize=(7, 4))ax = plt.subplot(121)ax.set_aspect(1)plt.plot(np.arange(10))plt.xlabel('this is a xlabel\n(with newlines!)')plt.ylabel('this is vertical\ntest', multialignment='center')plt.text(2, 7, 'this is\nyet another test', rotation=45, horizontalalignment='center', verticala...
stix_fonts_demo
STIX 字体演示 12345678910111213141516171819202122232425import matplotlib.pyplot as pltimport numpy as nptests = [ r'$\mathcircled{123} \mathrm{\mathcircled{123}}' r' \mathbf{\mathcircled{123}}$', r'$\mathsf{Sans \Omega} \mathrm{\mathsf{Sans \Omega}}' r' \mathbf{\mathsf{Sans \Omega}}$', r'$\mathtt{Monosp...
mathtext_examples
数学文本例子Matplotlib的数学渲染引擎的选定功能。 Out: 123456780 $W^{3\beta}_{\delta_1 \rho_1 \sigma_2} = U^{3\beta}_{\delta_1 \rho_1} + \frac{1}{8 \pi 2} \int^{\alpha_2}_{\alpha_2} d \alpha^\prime_2 \left[\frac{ U^{2\beta}_{\delta_1 \rho_1} - \alpha^\prime_2U^{1\beta}_{\rho_1 \sigma_2} }{U^{0\beta}_{\rho_1 \sigma_2}}\right]$1 $\alpha_i > \bet...
tex_demo
使用纹理渲染数学方程如果设置了rc参数text.usetex,则可以使用TeX渲染所有matplotlib文本。这当前在agg和ps后端上工作,并且要求你在系统上正确安装了Text render With LaTeX教程中描述的tex和其他依赖项。第一次运行脚本时,你将看到tex和相关工具的大量输出。下一次,运行可能是静默的,因为许多信息都被缓存。 注意如何使用unicode提供y轴的标签! 1234567891011121314151617import numpy as npimport matplotlibmatplotlib.rcParams['text.usetex'] = Trueimport matplotlib.pyplot as pltt = np.linspace(0.0, 1.0, 100)s = np.cos(4 * np.pi * t) + 2fig, ax = plt.subplots(figsize=(6, 4), tight_layout=True)ax.plot(t, s)ax.set_xlabel(r'\textb...
text_alignment
精确文本布局你可以在数据或轴 (0, 1) 坐标中精确布局文本。此示例显示了文本布局的一些对齐和旋转规范。 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071import matplotlib.pyplot as plt# Build a rectangle in axes coordsleft, width = .25, .5bottom, height = .25, .5right = left + widthtop = bottom + heightax = plt.gca()p = plt.Rectangle((left, bottom), width, height, fill=False)p.set_transform(ax.transAxes)p.set_clip_on(False)ax.add_patch(p)ax.text(left, bottom...
text_rotation
默认文本旋转演示默认情况下,Matplotlib执行文本布局的方式与某些人相反,因此本示例旨在使其更加清晰。 文本由其边界框(围绕墨水矩形的矩形框)对齐。 操作的顺序是旋转然后对齐。 基本上,文本以x,y位置为中心,围绕此点旋转,然后根据旋转文本的边界框对齐。 因此,如果指定left,bottom alignment,则旋转文本的边界框的左下角将位于文本的x,y坐标处。 但是一张图片胜过千言万语! 12345678910111213141516171819202122232425262728293031import matplotlib.pyplot as pltimport numpy as npdef addtext(ax, props): ax.text(0.5, 0.5, 'text 0', props, rotation=0) ax.text(1.5, 0.5, 'text 45', props, rotation=45) ax.text(2.5, 0.5, 'text 135', prop...
text_fontdict
使用字典控制文本和标签的样式此示例显示如何通过创建跨多个函数传递的选项字典来跨多个文本对象和标签共享参数。 12345678910111213141516171819202122import numpy as npimport matplotlib.pyplot as pltfont = {'family': 'serif', 'color': 'darkred', 'weight': 'normal', 'size': 16, }x = np.linspace(0.0, 5.0, 100)y = np.cos(2*np.pi*x) * np.exp(-x)plt.plot(x, y, 'k')plt.title('Damped exponential decay', fontdict=font)plt.text(2, 0....
text_rotation_relative_to_line
相对线的文本旋转matplotlib中的文本对象通常相对于屏幕坐标系旋转(即,无论轴如何更改,沿水平和垂直之间的直线旋转45度打印文本)。但是,有时需要围绕打印上的某个内容旋转文本。在这种情况下,正确的角度将不是该对象在打印坐标系中的角度,而是该对象在屏幕坐标系中显示的角度。此角度是通过将角度从打印转换为屏幕坐标系来找到的,如下面的示例所示。 12345678910111213141516171819202122232425import matplotlib.pyplot as pltimport numpy as np# Plot diagonal line (45 degrees)h = plt.plot(np.arange(0, 10), np.arange(0, 10))# set limits so that it no longer looks on screen to be 45 degreesplt.xlim([-10, 20])# Locations to plot textl1 = np.array((1, 1))l2 = np.array((5, 5))#...














