align_ylabels
对齐y标签这里显示了两种方法,一种是使用对 Figure.align_ylabels 的简短调用,另一种是使用手动方式来对齐标签。 1234567891011121314151617181920212223242526272829303132333435363738import numpy as npimport matplotlib.pyplot as pltdef make_plot(axs): box = dict(facecolor='yellow', pad=5, alpha=0.2) # Fixing random state for reproducibility np.random.seed(19680801) ax1 = axs[0, 0] ax1.plot(2000*np.random.rand(10)) ax1.set_title('ylabels not aligned') ax1.set_ylabel('misaligned 1', bbox=box) ...
annotation_basic
注释一个图像此示例显示如何使用指向提供的坐标的箭头注释绘图。我们修改箭头的默认值,以“缩小”它。 有关注释功能的完整概述,另请参阅注释教程。 1234567891011121314import numpy as npimport matplotlib.pyplot as pltfig, ax = plt.subplots()t = np.arange(0.0, 5.0, 0.01)s = np.cos(2*np.pi*t)line, = ax.plot(t, s, lw=2)ax.annotate('local max', xy=(2, 1), xytext=(3, 1.5), arrowprops=dict(facecolor='black', shrink=0.05), )ax.set_ylim(-2, 2)plt.show() 参考此示例中显示了以下函数,方法,类和模块的使用: 123import matplotlibmatplotlib.axes.Axes.annotatematplo...
annotation_polar
注释极坐标此示例显示如何在极坐标图上创建注释。 有关注释功能的完整概述,另请参阅注释教程。 123456789101112131415161718192021import numpy as npimport matplotlib.pyplot as pltfig = plt.figure()ax = fig.add_subplot(111, polar=True)r = np.arange(0,1,0.001)theta = 2 * 2*np.pi * rline, = ax.plot(theta, r, color='#ee8d18', lw=3)ind = 800thisr, thistheta = r[ind], theta[ind]ax.plot([thistheta], [thisr], 'o')ax.annotate('a polar annotation', xy=(thistheta, thisr), # theta, radius xytext=(0.05,...
auto_subplots_adjust
自动调整子图自动调整子图参数。 此示例显示了一种使用draw_event上的回调从ticklabels范围确定subplot参数的方法。 请注意,使用tight_layout或 constrained_layout 可以实现类似的结果; 此示例显示了如何自定义子图参数调整。 12345678910111213141516171819202122232425262728import matplotlib.pyplot as pltimport matplotlib.transforms as mtransformsfig, ax = plt.subplots()ax.plot(range(10))ax.set_yticks((2,5,7))labels = ax.set_yticklabels(('really, really, really', 'long', 'labels'))def on_draw(event): bboxes = [] for label in labels: bbox = l...
boxplot_demo_pyplot
Boxplot 演示boxplot 的代码示例。 123456789101112import numpy as npimport matplotlib.pyplot as plt# Fixing random state for reproducibilitynp.random.seed(19680801)# fake up some dataspread = np.random.rand(50) * 100center = np.ones(25) * 50flier_high = np.random.rand(10) * 100 + 100flier_low = np.random.rand(10) * -100data = np.concatenate((spread, center, flier_high, flier_low)) 123fig1, ax1 = plt.subplots()ax1.set_title('Basic Plot')ax1.boxplot(data) 123fig2, ax2 = plt.subplots()ax2.set...
dollar_ticks
美元符刻度使用 FormatStrFormatter 在y轴标签上添加美元符号。 12345678910111213141516171819import numpy as npimport matplotlib.pyplot as pltimport matplotlib.ticker as ticker# Fixing random state for reproducibilitynp.random.seed(19680801)fig, ax = plt.subplots()ax.plot(100*np.random.rand(20))formatter = ticker.FormatStrFormatter('$%1.2f')ax.yaxis.set_major_formatter(formatter)for tick in ax.yaxis.get_major_ticks(): tick.label1On = False tick.label2On = True tick.label2.set_color('green...
fig_axes_customize_simple
简单的图轴自定义自定义简单绘图的背景,标签和刻度。 1import matplotlib.pyplot as plt 用 plt.figure 创建一个 matplotlib.figure.Figure 实例 12345678910111213141516171819202122fig = plt.figure()rect = fig.patch # a rectangle instancerect.set_facecolor('lightgoldenrodyellow')ax1 = fig.add_axes([0.1, 0.3, 0.4, 0.4])rect = ax1.patchrect.set_facecolor('lightslategray')for label in ax1.xaxis.get_ticklabels(): # label is a Text instance label.set_color('red') label.set_rotation(45) label.set...
fig_axes_labels_simple
简单的图轴标记标记图的轴。 12345678910111213141516171819202122import numpy as npimport matplotlib.pyplot as pltfig = plt.figure()fig.subplots_adjust(top=0.8)ax1 = fig.add_subplot(211)ax1.set_ylabel('volts')ax1.set_title('a sine wave')t = np.arange(0.0, 1.0, 0.01)s = np.sin(2*np.pi*t)line, = ax1.plot(t, s, color='blue', lw=2)# Fixing random state for reproducibilitynp.random.seed(19680801)ax2 = fig.add_axes([0.15, 0.1, 0.7, 0.3])n, bins, patches = ax2.hist(np.random.randn(1000...
fig_x
X图添加线条到图形(没有轴)。 12345678910111213import matplotlib.pyplot as pltimport matplotlib.lines as linesfig = plt.figure()l1 = lines.Line2D([0, 1], [0, 1], transform=fig.transFigure, figure=fig)l2 = lines.Line2D([0, 1], [1, 0], transform=fig.transFigure, figure=fig)fig.lines.extend([l1, l2])plt.show() 参考此示例中显示了以下函数,方法,类和模块的使用: 1234import matplotlibmatplotlib.pyplot.figurematplotlib.linesmatplotlib.lines.Line2D 下载这个示例 下载python源码: fig_x.py 下载Jupyter notebook: fig_x.ipynb
pyplot_formatstr
Pyplot 格式字符串(Formatstr)使用格式字符串为绘图(plot)着色并设置其标记。 1234import matplotlib.pyplot as pltplt.plot([1,2,3,4], [1,4,9,16], 'ro')plt.axis([0, 6, 0, 20])plt.show() 参考此示例中显示了以下函数,方法,类和模块的使用: 123import matplotlibmatplotlib.pyplot.plotmatplotlib.axes.Axes.plot 下载这个示例 下载python源码: pyplot_formatstr.py 下载Jupyter notebook: pyplot_formatstr.ipynb














