whats_new_98_4_fill_between
填充交叉区域填充两条曲线之间的区域。 1234567891011121314import matplotlib.pyplot as pltimport numpy as npx = np.arange(-5, 5, 0.01)y1 = -5*x*x + x + 10y2 = 5*x*x + xfig, ax = plt.subplots()ax.plot(x, y1, x, y2, color='black')ax.fill_between(x, y1, y2, where=y2 >y1, facecolor='yellow', alpha=0.5)ax.fill_between(x, y1, y2, where=y2 <=y1, facecolor='red', alpha=0.5)ax.set_title('Fill Between')plt.show() 参考此示例中显示了以下函数,方法,类和模块的使用: 12import matplotlibmatplotlib.axes.Ax...
whats_new_98_4_legend
0.98.4版本图例新特性创建图例并使用阴影和长方体对其进行调整。 1234567891011121314import matplotlib.pyplot as pltimport numpy as npax = plt.subplot(111)t1 = np.arange(0.0, 1.0, 0.01)for n in [1, 2, 3, 4]: plt.plot(t1, t1**n, label="n=%d"%(n,))leg = plt.legend(loc='best', ncol=2, mode="expand", shadow=True, fancybox=True)leg.get_frame().set_alpha(0.5)plt.show() 参考此示例显示了以下函数、方法、类和模块的使用: 12345import matplotlibmatplotlib.axes.Axes.legendmatplotlib.pyplot.legendmatplotlib.legend.Legendmatplo...
whats_new_99_axes_grid
0.99版本轴网格新特性创建RGB合成图像。 1234567891011121314151617181920212223242526272829303132333435363738394041424344import numpy as npimport matplotlib.pyplot as pltfrom mpl_toolkits.axes_grid1.axes_rgb import RGBAxesdef get_demo_image(): # prepare image delta = 0.5 extent = (-3, 4, -4, 3) x = np.arange(-3.0, 4.001, delta) y = np.arange(-4.0, 3.001, delta) X, Y = np.meshgrid(x, y) Z1 = np.exp(-X**2 - Y**2) Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2) Z = (Z1 - Z2) * 2 return Z, exten...
whats_new_99_spines
0.99版本新增Spines对象12345678910111213141516171819202122232425262728293031323334353637383940414243444546import matplotlib.pyplot as pltimport numpy as npdef adjust_spines(ax,spines): for loc, spine in ax.spines.items(): if loc in spines: spine.set_position(('outward',10)) # outward by 10 points else: spine.set_color('none') # don't draw spine # turn off ticks where there is no spine if 'left' in spines: ax.yaxis...
whats_new_99_mplot3d
0.99版本新增Mplot3d对象创建3D曲面图。 12345678910111213141516import numpy as npimport matplotlib.pyplot as pltfrom matplotlib import cmfrom mpl_toolkits.mplot3d import Axes3DX = np.arange(-5, 5, 0.25)Y = np.arange(-5, 5, 0.25)X, Y = np.meshgrid(X, Y)R = np.sqrt(X**2 + Y**2)Z = np.sin(R)fig = plt.figure()ax = Axes3D(fig)ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.viridis)plt.show() 参考此示例中显示了以下函数,方法,类和模块的使用: 123import mpl_toolkitsmpl_toolkits.mplot3d.Axes3Dmpl_toolkits.mplot3d.Axes3D.plot_surf...
custom_scale
自定义比例尺通过在墨卡托投影中实现纬度数据的缩放用途来创建自定义比例。 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174import numpy as npfrom numpy import mafrom mat...
aspect_loglog
双对数 1234567891011121314151617181920import matplotlib.pyplot as pltfig, (ax1, ax2) = plt.subplots(1, 2)ax1.set_xscale("log")ax1.set_yscale("log")ax1.set_xlim(1e1, 1e3)ax1.set_ylim(1e2, 1e3)ax1.set_aspect(1)ax1.set_title("adjustable = box")ax2.set_xscale("log")ax2.set_yscale("log")ax2.set_adjustable("datalim")ax2.plot([1, 3, 10], [1, 9, 100], "o-")ax2.set_xlim(1e-1, 1e2)ax2.set_ylim(1e-1, 1e3)ax2.set_aspect(1)ax2.set_title(&q...
index
刻度、比例尺这些示例介绍了如何在Matplotlib中处理不同的比例。
log_bar
对数条形图绘制具有对数y轴的条形图。 12345678910111213141516171819202122import matplotlib.pyplot as pltimport numpy as npdata = ((3, 1000), (10, 3), (100, 30), (500, 800), (50, 1))dim = len(data[0])w = 0.75dimw = w / dimfig, ax = plt.subplots()x = np.arange(len(data))for i in range(len(data[0])): y = [d[i] for d in data] b = ax.bar(x + i * dimw, y, dimw, bottom=0.001)ax.set_xticks(x + dimw / 2, map(str, x))ax.set_yscale('log')ax.set_xlabel('x')ax.set_ylabel('y')plt.show() ...
log_demo
对数演示具有对数轴的图的示例。 1234567891011121314151617181920212223242526272829303132333435363738import numpy as npimport matplotlib.pyplot as plt# Data for plottingt = np.arange(0.01, 20.0, 0.01)# Create figurefig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2)# log y axisax1.semilogy(t, np.exp(-t / 5.0))ax1.set(title='semilogy')ax1.grid()# log x axisax2.semilogx(t, np.sin(2 * np.pi * t))ax2.set(title='semilogx')ax2.grid()# log x and y axisax3.loglog(t, 20 * np.exp(-t / 10.0), basex=2)...














