step_demo
阶梯图示例阶梯图例子: 12345678910111213141516171819202122232425import numpy as npfrom numpy import maimport matplotlib.pyplot as pltx = np.arange(1, 7, 0.4)y0 = np.sin(x)y = y0.copy() + 2.5plt.step(x, y, label='pre (default)')y -= 0.5plt.step(x, y, where='mid', label='mid')y -= 0.5plt.step(x, y, where='post', label='post')y = ma.masked_where((y0 > -0.15) & (y0 < 0.15), y - 0.5)plt.step(x, y, label='masked (pre)')plt.legend()plt.xlim...
xcorr_acorr_demo
交叉和自动关联演示使用互相关(xcorr)和自相关(acorr)图的示例。 12345678910111213141516171819import matplotlib.pyplot as pltimport numpy as np# Fixing random state for reproducibilitynp.random.seed(19680801)x, y = np.random.randn(2, 100)fig, [ax1, ax2] = plt.subplots(2, 1, sharex=True)ax1.xcorr(x, y, usevlines=True, maxlags=50, normed=True, lw=2)ax1.grid(True)ax1.axhline(0, color='black', lw=2)ax2.acorr(x, usevlines=True, normed=True, maxlags=50, lw=2)ax2.grid(True)ax2.axhline(0, color='black', lw...
vline_hline_demo
hlines和vlines此示例展示了hlines和vlines的功能。 123456789101112131415161718192021222324import matplotlib.pyplot as pltimport numpy as npt = np.arange(0.0, 5.0, 0.1)s = np.exp(-t) + np.sin(2 * np.pi * t) + 1nse = np.random.normal(0.0, 0.3, t.shape) * sfig, (vax, hax) = plt.subplots(1, 2, figsize=(12, 6))vax.plot(t, s + nse, '^')vax.vlines(t, [0], s)# By using ``transform=vax.get_xaxis_transform()`` the y coordinates are scaled# such that 0 maps to the bottom of the axes and 1 to the top.vax.vl...
agg_buffer
Agg缓冲区使用后端AGG以RGB字符串的形式访问地物画布,然后将其转换为数组并将其传递给Pillow进行渲染。 12345678910111213141516171819202122import numpy as npfrom matplotlib.backends.backend_agg import FigureCanvasAggimport matplotlib.pyplot as pltplt.plot([1, 2, 3])canvas = plt.get_current_fig_manager().canvasagg = canvas.switch_backends(FigureCanvasAgg)agg.draw()s, (width, height) = agg.print_to_buffer()# Convert to a NumPy array.X = np.fromstring(s, np.uint8).reshape((height, width, 4))# Pass off to PIL.from PIL import Imageim = Image....
agg_buffer_to_array
Agg缓冲区转换数组将渲染图形转换为其图像(NumPy数组)表示形式。 1234567891011121314151617import matplotlib.pyplot as pltimport numpy as np# make an agg figurefig, ax = plt.subplots()ax.plot([1, 2, 3])ax.set_title('a simple figure')fig.canvas.draw()# grab the pixel buffer and dump it into a numpy arrayX = np.array(fig.canvas.renderer._renderer)# now display the array X as an Axes in a new figurefig2 = plt.figure()ax2 = fig2.add_subplot(111, frameon=False)ax2.imshow(X)plt.show() 下载这个示例 下载python源码: agg_buffer_...
anchored_artists
锚定艺术家对象这个使用没有辅助类的锚定对象的示例在Matplotlib axes_grid1 Toolkit中找到。此版本的图与Simple Anchored Artists中的版本类似,但它仅使用matplotlib命名空间实现,没有其他工具包的帮助。 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115from matplotlib import pyplot as pltfrom matplotlib.patches import Rectangle, Ellipsefrom matplotlib.offsetbox import ( Anchored...
bbox_intersect
改变与盒子相交的线条的颜色与矩形相交的线条用红色着色,而其他线条用蓝色线条留下。此示例展示了intersect_bbox函数。 123456789101112131415161718192021222324252627import numpy as npimport matplotlib.pyplot as pltfrom matplotlib.transforms import Bboxfrom matplotlib.path import Path# Fixing random state for reproducibilitynp.random.seed(19680801)left, bottom, width, height = (-1, -1, 2, 2)rect = plt.Rectangle((left, bottom), width, height, facecolor="#aaaaaa")fig, ax = plt.subplots()ax.add_patch(rect)bbox = Bbox.from_bounds(left, botto...
contour_manual
Contour手册使用ContourSet显示自己的轮廓线和多边形的示例。 123import matplotlib.pyplot as pltfrom matplotlib.contour import ContourSetimport matplotlib.cm as cm 每个级别的轮廓线是多边形的列表/元组。 123lines0 = [[[0, 0], [0, 4]]]lines1 = [[[2, 0], [1, 2], [1, 3]]]lines2 = [[[3, 0], [3, 2]], [[3, 3], [3, 4]]] # Note two lines. 两个级别之间的填充等高线也是多边形的列表/元组。点可以顺时针或逆时针排列。 123filled01 = [[[0, 0], [0, 4], [1, 3], [1, 2], [2, 0]]]filled12 = [[[2, 0], [3, 0], [3, 2], [1, 3], [1, 2]], # Note two polygons. [[1, 4], [3, ...
coords_report
坐标报告覆盖coords的默认报告。 12345678910111213141516171819import matplotlib.pyplot as pltimport numpy as npdef millions(x): return '$%1.1fM' % (x*1e-6)# Fixing random state for reproducibilitynp.random.seed(19680801)x = np.random.rand(20)y = 1e7*np.random.rand(20)fig, ax = plt.subplots()ax.fmt_ydata = millionsplt.plot(x, y, 'o')plt.show() 下载这个示例 下载python源码: coords_report.py 下载Jupyter notebook: coords_report.ipynb
custom_projection
自定义投影通过减轻Matplotlib的许多功能来展示Hammer投影。 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189...














