bachelors_degrees_by_gender
按性别分列的学士学位包含多个时间序列的图形,其中演示了打印框架、刻度线和标签以及线图特性的广泛自定义样式。 还演示了文本标签沿右边缘的自定义放置,作为传统图例的替代方法。 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103import numpy as npimport matplotlib.pyplot as pltfrom matplotlib.cbook import get_sample_datafname = get_sample_data('percent_bachelors_degrees_women_usa.csv', asfileobj=False)...
anatomy
解剖图下图显示了组成一个图的几个matplotlib元素的名称。 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137import numpy as npimport matplotlib.pyplot as pltfrom matplotlib.ticker import AutoMinorLocator, MultipleLocator, FuncFormatternp.random.seed(19680801)X = np.li...
firefox
绘制火狐浏览器logo此示例显示如何使用路径和修补程序创建Firefox徽标。 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263import reimport numpy as npimport matplotlib.pyplot as pltfrom matplotlib.path import Pathimport matplotlib.patches as patches# From: http://raphaeljs.com/icons/#firefoxfirefox = "M28.4,22.469c0.479-0.964,0.851-1.991,1.095-3.066c0.953-3.661,0.666-6.854,0.666-6.854l-0.327,2.104c0,0-0.469-3.896-1.044-5.353c-0.881-2.231-1.273-2.214-1.2...
mandelbrot
阴影和增强标准化渲染通过使用与幂归一化色图(gamma = 0.3)相关联的归一化重新计数,可以改善Mandelbrot集渲染。 由于阴影,渲染可以进一步增强。 maxiter给出了计算的精度。 在大多数现代笔记本电脑上,maxiter = 200应该需要几秒钟。 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263import numpy as npdef mandelbrot_set(xmin, xmax, ymin, ymax, xn, yn, maxiter, horizon=2.0): X = np.linspace(xmin, xmax, xn).astype(np.float32) Y = np.linspace(ymin, ymax, yn).astype(np.float32) C = X + Y[:, None] * 1j N = np...
integral
积分作为曲线下面积虽然这是一个简单的例子,但它展示了一些重要的调整: 带有自定义颜色和线宽的简单线条图。 使用Polygon补丁创建的阴影区域。 带有mathtext渲染的文本标签。 figtext调用标记x轴和y轴。 使用轴刺来隐藏顶部和右侧脊柱。 自定义刻度线和标签。 123456789101112131415161718192021222324252627282930313233343536373839import numpy as npimport matplotlib.pyplot as pltfrom matplotlib.patches import Polygondef func(x): return (x - 3) * (x - 5) * (x - 7) + 85a, b = 2, 9 # integral limitsx = np.linspace(0, 10)y = func(x)fig, ax = plt.subplots()plt.plot(x, y, 'r', linewidth=2)plt.ylim(ymin=0)#...
xkcd
XKCD演示如何创建类似xkcd的绘图。 12import matplotlib.pyplot as pltimport numpy as np 123456789101112131415161718192021222324252627with plt.xkcd(): # Based on "Stove Ownership" from XKCD by Randall Monroe # http://xkcd.com/418/ fig = plt.figure() ax = fig.add_axes((0.1, 0.2, 0.8, 0.7)) ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') plt.xticks([]) plt.yticks([]) ax.set_ylim([-30, 10]) data = np.ones(10...
advanced_hillshading
晕渲用阴影图展示一些常见的技巧。 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768import numpy as npimport matplotlib.pyplot as pltfrom matplotlib.colors import LightSource, Normalizedef display_colorbar(): """Display a correct numeric colorbar for a shaded plot.""" y, x = np.mgrid[-4:2:200j, -4:2:200j] z = 10 * np.cos(x**2 + y**2) cmap = plt.cm.copper ls = LightSource(315, 45) rgb...
hinton_demo
Hinton图Hinton图对于可视化2D阵列的值(例如,权重矩阵)是有用的:正值和负值分别由白色和黑色方块表示,并且每个方块的大小表示每个值的大小。 David Warde-Farley在SciPy Cookbook上的初步想法 123456789101112131415161718192021222324252627282930313233import numpy as npimport matplotlib.pyplot as pltdef hinton(matrix, max_weight=None, ax=None): """Draw Hinton diagram for visualizing a weight matrix.""" ax = ax if ax is not None else plt.gca() if not max_weight: max_weight = 2 ** np.ceil(np.log(np.abs(matrix).max()) / np.log...
anscombe
Anscombe的四重奏 输出: 1234mean=7.50, std=1.94, r=0.82mean=7.50, std=1.94, r=0.82mean=7.50, std=1.94, r=0.82mean=7.50, std=1.94, r=0.82 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758"""Edward Tufte uses this example from Anscombe to show 4 datasets of xand y that have the same mean, standard deviation, and regressionline, but which are qualitatively different.matplotlib fun for a rainy day"""import matplotli...
leftventricle_bulleye
左心室靶心该示例演示了如何为美国心脏协会(AHA)推荐的左心室创建17段模型。 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188...














