color_cycler
用cycler定型演示自定义特性-循环设置以控制多行绘制的颜色和其他样式特性。 此示例演示了两种不同的API: 1234567891011121314151617181920212223242526272829from cycler import cyclerimport numpy as npimport matplotlib.pyplot as pltx = np.linspace(0, 2 * np.pi)offsets = np.linspace(0, 2*np.pi, 4, endpoint=False)# Create array with shifted-sine curve along each columnyy = np.transpose([np.sin(x + phi) for phi in offsets])# 1. Setting prop cycle on default rc parameterplt.rc('lines', linewidth=4)plt.rc('axes', prop_cycle=(cycl...
color_demo
基本颜色演示Matplotlib为您提供了8种指定颜色的方法: 在[0, 1]中的浮点值的RGB或RGBA元组(例如 (0.1, 0.2, 0.5) 或 (0.1, 0.2, 0.5, 0.3))。RGBA是红色,绿色,蓝色,Alpha的缩写; 十六进制RGB或RGBA字符串 (例如: '#0F0F0F' 或者 '#0F0F0F0F'); [0, 1]中浮点值的字符串表示,包括灰度级(例如,’0.5’); 单字母字符串,例如这些其中之一:{'b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'}; 一个 X11/CSS4 (“html”) 颜色名称, 例如:”blue”; 来自xkcd的颜色调研的名称,前缀为 ‘xkcd:’ (例如:“xkcd:sky blue”); 一个 “Cn” 颜色规范,即 ‘C’ 后跟一个数字,这是默认属性循环的索引(matplotlib.rcParams[...
index
颜色相关示例有关matplotlib中可用的色彩映射的更深入信息及其属性的说明,请参阅colormaps教程。
colorbar_basics
颜色条通过指定可映射对象(此处为imshow返回的 AxesImage )和要将颜色条附加到的轴来使用 colorbar。 1234567891011121314151617181920212223242526272829303132333435import numpy as npimport matplotlib.pyplot as plt# setup some generic dataN = 37x, y = np.mgrid[:N, :N]Z = (np.cos(x*0.2) + np.sin(y*0.3))# mask out the negative and positive values, respectivelyZpos = np.ma.masked_less(Z, 0)Zneg = np.ma.masked_greater(Z, 0)fig, (ax1, ax2, ax3) = plt.subplots(figsize=(13, 3), ncols=3)# plot just the positive data and save the# color "...
colormap_reference
Colormap参考Matplotlib附带的色彩映射参考。 通过将 _r 附加到名称(例如,viridis_r),可以获得每个这些颜色映射的反转版本。 请参阅在Matplotlib中选择Colormaps以深入讨论色彩映射,包括colorblind-friendlyliness。 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455import numpy as npimport matplotlib.pyplot as pltcmaps = [('Perceptually Uniform Sequential', [ 'viridis', 'plasma', 'inferno', 'magma', 'cividis']), ('Sequential', ...
custom_cmap
从颜色列表创建颜色映射有关创建和操作色彩映射的更多详细信息,请参阅在Matplotlib中创建色彩映射。 可以使用LinearSegmentedColormap的from_list()方法从颜色列表创建颜色映射。您必须传递一个RGB元组列表,用于定义从0到1的颜色混合。 创建自定义色彩映射也可以为色彩映射创建自定义映射。 这是通过创建字典来实现的,该字典指定RGB通道如何从cmap的一端变为另一端。 示例:假设您希望红色在下半部分从0增加到1,绿色在中间半部分增加到相同,而在上半部分则为蓝色。 然后你会用: 123456789101112cdict = {'red': ((0.0, 0.0, 0.0), (0.5, 1.0, 1.0), (1.0, 1.0, 1.0)), 'green': ((0.0, 0.0, 0.0), (0.25, 0.0, 0.0), ...
3D
Frontpage 3D示例此示例再现Frontpage 3D示例。 1234567891011121314151617181920212223242526272829303132# This import registers the 3D projection, but is otherwise unused.from mpl_toolkits.mplot3d import Axes3D # noqa: F401 unused importfrom matplotlib import cbookfrom matplotlib import cmfrom matplotlib.colors import LightSourceimport matplotlib.pyplot as pltimport numpy as npfilename = cbook.get_sample_data('jacksboro_fault_dem.npz', asfileobj=False)with np.load(filename) as dem: z = dem[&...
named_colors
可视化命名颜色这绘制了matplotlib中支持的命名颜色列表。 请注意,也支持xkcd颜色,但为简洁起见,此处未列出。 有关matplotlib中颜色的更多信息,请参阅: 指定颜色教程; matplotlib.colors API; 颜色演示。 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768import matplotlib.pyplot as pltimport matplotlib.colors as mcolorsdef plot_colortable(colors, title, sort_colors=True, emptycols=0): cell_width = 212 cell_height = 22 swatch_width = 48 margin = 12 topmargin = 40 # Sort colors ...
histogram
Frontpage 直方图示例此示例再现Frontpage 直方图示例。 1234567891011121314import matplotlib.pyplot as pltimport numpy as nprandom_state = np.random.RandomState(19680801)X = random_state.randn(10000)fig, ax = plt.subplots()ax.hist(X, bins=25, density=True)x = np.linspace(-5, 5, 1000)ax.plot(x, 1 / np.sqrt(2*np.pi) * np.exp(-(x**2)/2), linewidth=4)ax.set_xticks([])ax.set_yticks([])fig.savefig("histogram_frontpage.png", dpi=25) # results in 160x120 px image 下载这个示例 下载python源码: histogram.py 下载Jupyter n...
contour
Frontpage 轮廓示例此示例再现Frontpage 轮廓示例。 1234567891011121314151617181920212223242526import matplotlib.pyplot as pltimport numpy as npfrom matplotlib import cmextent = (-3, 3, -3, 3)delta = 0.5x = 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 - Z2norm = cm.colors.Normalize(vmax=abs(Z).max(), vmin=-abs(Z).max())fig, ax = plt.subplots()cset1 = ax.contourf( X, Y, Z, 40, norm=norm)ax.set_x...














