titles_demo
标题组演示Matplotlib可以显示打印标题居中,与一组轴的左侧齐平,并与一组轴的右侧齐平。 123456789import matplotlib.pyplot as pltplt.plot(range(10))plt.title('Center Title')plt.title('Left Title', loc='left')plt.title('Right Title', loc='right')plt.show() 下载这个示例 下载python源码: titles_demo.py 下载Jupyter notebook: titles_demo.ipynb
unicode_minus
Unicode 负表示您可以使用正确的排版Unicode 负号或ASCII连字符表示负好,有些开发者倾向于这样做。 rcParams[“axes.unicode_minus”]控制默认行为。 默认是使用Unicode负号。 12345678910111213import numpy as npimport matplotlibimport matplotlib.pyplot as plt# Fixing random state for reproducibilitynp.random.seed(19680801)matplotlib.rcParams['axes.unicode_minus'] = Falsefig, ax = plt.subplots()ax.plot(10*np.random.randn(100), 10*np.random.randn(100), 'o')ax.set_title('Using hyphen instead of Unicode minus')plt.show() 下载这个示...
usetex_baseline_test
Usetex基线测试 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566import matplotlib.pyplot as pltimport matplotlib.axes as maxesfrom matplotlib import rcParamsrcParams['text.usetex'] = Trueclass Axes(maxes.Axes): """ A hackish way to simultaneously draw texts w/ usetex=True and usetex=False in the same figure. It does not work in the ps backend. """ def __init__(self, *ar...
watermark_text
文字水印添加文字水印。 12345678910111213141516import numpy as npimport matplotlib.pyplot as plt# Fixing random state for reproducibilitynp.random.seed(19680801)fig, ax = plt.subplots()ax.plot(np.random.rand(20), '-o', ms=20, lw=2, alpha=0.7, mfc='orange')ax.grid()fig.text(0.95, 0.05, 'Property of MPL', fontsize=50, color='gray', ha='right', va='bottom', alpha=0.5)plt.show() 参考此示例中显示了以下函数,方法,类和模块的使用: 12import matplotlibmatplotl...
usetex_demo
Usetex 演示演示如何在绘制中使用latex。 另请参阅 “使用latex进行文本渲染” 指南。 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859import numpy as npimport matplotlib.pyplot as pltplt.rc('text', usetex=True)# interface tracking profilesN = 500delta = 0.6X = np.linspace(-1, 1, N)plt.plot(X, (1 - np.tanh(4 * X / delta)) / 2, # phase field tanh profiles X, (1.4 + np.tanh(4 * X / delta)) / 4, "C2", # composition profile X, X &l...
usetex_fonteffects
Usetex 字体效果此脚本演示了pdf usetex现在支持pdftex.map中指定的字体效果。 12345678910111213141516171819202122import matplotlibimport matplotlib.pyplot as pltmatplotlib.rc('text', usetex=True)def setfont(font): return r'\font\a %s at 14pt\a ' % fontfor y, font, text in zip(range(5), ['ptmr8r', 'ptmri8r', 'ptmro8r', 'ptmr8rn', 'ptmrr8re'], ['Nimbus Roman No9 L ' ...
auto_ticks
自动设置记号标签设置刻度自动放置的行为。 如果您没有明确设置刻度位置/标签,Matplotlib将尝试根据显示的数据及其限制自动选择它们。 默认情况下,这会尝试选择沿轴分布的刻度位置: 123456789import matplotlib.pyplot as pltimport numpy as npnp.random.seed(19680801)fig, ax = plt.subplots()dots = np.arange(10) / 100. + .03x, y = np.meshgrid(dots, dots)data = [x.ravel(), y.ravel()]ax.scatter(*data, c=data[1]) 有时选择均匀分布的刻度会产生奇怪的刻度数。 如果您希望Matplotlib保持位于圆形数字的刻度线,则可以使用以下rcParams值更改此行为: 123456print(plt.rcParams['axes.autolimit_mode'])# Now change this value and see the res...
centered_ticklabels
居中TickLabels有时将ticklabels置于中心是件好事。 Matplotlib目前将标签与刻度线关联,标签可以使用水平对齐属性对齐“中心”,“左”或“右”: 1ax.xaxis.set_tick_params(horizontalalignment='right') 但这并没有帮助将标签置于刻度之间。一种解决方案是“伪造它”。 使用次要刻度在主要刻度之间放置一个刻度。这是一个标记月份的示例,以ticks为中心。 12345678910111213141516171819202122232425262728293031import numpy as npimport matplotlib.cbook as cbookimport matplotlib.dates as datesimport matplotlib.ticker as tickerimport matplotlib.pyplot as plt# load some financial data; apple's stock pricewith cbook.get_samp...
colorbar_tick_labelling_demo
颜色栏刻度标签演示为彩条生成自定义标签。 供稿人:Scott Sinclair 1234import matplotlib.pyplot as pltimport numpy as npfrom matplotlib import cmfrom numpy.random import randn 使用垂直(默认)颜色条创建绘图 12345678910fig, ax = plt.subplots()data = np.clip(randn(250, 250), -1, 1)cax = ax.imshow(data, interpolation='nearest', cmap=cm.coolwarm)ax.set_title('Gaussian noise with vertical colorbar')# Add colorbar, make sure to specify tick locations to match desired ticklabelscbar = fig.colorbar(cax, ticks=[-1, 0, 1])...
custom_ticker1
自定义Ticker1新的自动收报机代码旨在明确支持用户自定义滴答。matplotlib.ticker 的文档详细介绍了此过程。 该代码定义了许多预设代码,但主要设计为用户可扩展。 在此示例中,用户定义的函数用于格式化y轴上数百万美元的刻度。 1234567891011121314151617181920from matplotlib.ticker import FuncFormatterimport matplotlib.pyplot as pltimport numpy as npx = np.arange(4)money = [1.5e5, 2.5e6, 5.5e6, 2.0e7]def millions(x, pos): 'The two args are the value and tick position' return '$%1.1fM' % (x * 1e-6)formatter = FuncFormatter(millions)fig, ax = plt.subplots()ax.yaxis.set_majo...














