subplots_adjust
调整子图使用 subplots_adjust() 调整边距和子图的间距。 12345678910111213141516import matplotlib.pyplot as pltimport numpy as np# Fixing random state for reproducibilitynp.random.seed(19680801)plt.subplot(211)plt.imshow(np.random.random((100, 100)), cmap=plt.cm.BuPu_r)plt.subplot(212)plt.imshow(np.random.random((100, 100)), cmap=plt.cm.BuPu_r)plt.subplots_adjust(bottom=0.1, right=0.8, top=0.9)cax = plt.axes([0.85, 0.1, 0.075, 0.8])plt.colorbar(cax=cax)plt.show() 下载这个示例 下载python源码: subplots_adjust.py 下载Jupyter...
subplots_demo
子图演示大全说明 plt.subplots() 使用的示例。 此函数只需一次调用即可创建地物和子图网格,同时对各个图的创建方式提供合理的控制。要对子打印创建进行非常精细的调整,仍然可以直接在新地物上使用 add_subplot()。 12345678import matplotlib.pyplot as pltimport numpy as np# Simple data to display in various formsx = np.linspace(0, 2 * np.pi, 400)y = np.sin(x ** 2)plt.close('all') 只有一个图形和一个子图 123f, ax = plt.subplots()ax.plot(x, y)ax.set_title('Simple plot') 两个子图,轴数组是一维的。 1234f, axarr = plt.subplots(2, sharex=True)f.suptitle('Sharing X axis')axarr[0].plot(x, ...
two_scales
绘制不同比例在同一轴上的两个图样,具有不同的左右比例。 诀窍是使用共享同一x轴的两个不同的轴。您可以根据需要使用单独的 matplotlib.ticker 格式化程序和定位器,因为这两个轴是独立的。 这些轴是通过调用 Axes.twinx() 方法生成的。同样,Axes.twiny() 可用于生成共享y轴但具有不同顶部和底部比例的轴。 12345678910111213141516171819202122232425import numpy as npimport matplotlib.pyplot as plt# Create some mock datat = np.arange(0.01, 10.0, 0.01)data1 = np.exp(t)data2 = np.sin(2 * np.pi * t)fig, ax1 = plt.subplots()color = 'tab:red'ax1.set_xlabel('time (s)')ax1.set_ylabel('exp', color=color)ax1.pl...
zoom_inset_axes
缩放区域嵌入轴插入轴的示例和显示缩放位置的矩形。 12345678910111213141516171819202122232425262728293031323334353637import matplotlib.pyplot as pltimport numpy as npdef get_demo_image(): from matplotlib.cbook import get_sample_data import numpy as np f = get_sample_data("axes_grid/bivariate_normal.npy", asfileobj=False) z = np.load(f) # z is a numpy array of 15x15 return z, (-3, 4, -4, 3)fig, ax = plt.subplots(figsize=[5, 4])# make dataZ, extent = get_demo_image()Z2 = np.zeros([150, 150], d...
annotation_demo
注释图以下示例显示了如何在matplotlib中注释绘图。这包括突出显示特定的兴趣点,并使用各种视觉工具来引起对这一点的关注。有关matplotlib中注释和文本工具的更完整和深入的描述,请参阅注释教程。 1234import matplotlib.pyplot as pltfrom matplotlib.patches import Ellipseimport numpy as npfrom matplotlib.text import OffsetFrom 指定文本点和注释点您必须指定注释点 xy = (x, y) 来注释此点。另外,您可以为此注释的文本位置指定文本点 xytext=(x, y)。 (可选)您可以使用xycoords和textcoords的以下字符串之一指定xy和xytext的坐标系(默认为’data’): 123456789'figure points' : points from the lower left corner of the figure'figure pixels' : p...
accented_text
在matplotlib中使用重音文本Matplotlib通过tex、mathtext或unicode支持重音字符。 使用mathtext,提供以下重音:hat,breve,grave,bar,acute,tilde,vec,dot,ddot。所有这些语法都具有相同的语法,例如,要创建一个overbar,你可以使用 bar{o} 或者使用 o 元音来执行 ddot{o}。 还提供了快捷方式,例如: “o ‘e `e ~n .x ^y 12345678910111213141516171819202122import matplotlib.pyplot as plt# Mathtext demofig, ax = plt.subplots()ax.plot(range(10))ax.set_title(r'$\ddot{o}\acute{e}\grave{e}\hat{O}' r'\breve{i}\bar{A...
arrow_demo
# 箭头符号演示 新的花式箭头工具的箭头绘制示例。 代码由此人贡献: Rob Knight < rob@spot.colorado.edu > 用法:  12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015...
arrow_simple_demo
箭头符号简单演示 12345import matplotlib.pyplot as pltax = plt.axes()ax.arrow(0, 0, 0.5, 0.5, head_width=0.05, head_length=0.1, fc='k', ec='k')plt.show() 下载这个示例 下载python源码: arrow_simple_demo.py 下载Jupyter notebook: arrow_simple_demo.ipynb
autowrap
文本自动换行Matplotlib can wrap text automatically, but if it’s too long, the text will be displayed slightly outside of the boundaries of the axis anyways. 12345678910111213141516import matplotlib.pyplot as pltfig = plt.figure()plt.axis([0, 10, 0, 10])t = ("This is a really long string that I'd rather have wrapped so that it " "doesn't go outside of the figure, but if it's long enough it will go " "off the top or bottom!")plt.text(4, 1, t, ha=&...
custom_legends
撰写自定义图例Composing custom legends piece-by-piece. 注意: For more information on creating and customizing legends, see the following pages: Legend guide Legend Demo 有时您不希望与已绘制的数据明确关联的图例。例如,假设您已绘制了10行,但不希望每个行都显示图例项。如果您只是绘制线条并调用ax.legend(),您将获得以下内容: 1234567891011121314151617# sphinx_gallery_thumbnail_number = 2from matplotlib import rcParams, cyclerimport matplotlib.pyplot as pltimport numpy as np# Fixing random state for reproducibilitynp.random.seed(19680801)N = 10data = [np.logspace(0, 1, 100) ...














