dark_background
黑色的背景样式表此示例演示了 “dark_background” 样式,该样式使用白色表示通常为黑色的元素(文本,边框等)。请注意,并非所有绘图元素都默认为由rc参数定义的颜色。 12345678910111213141516171819import numpy as npimport matplotlib.pyplot as pltplt.style.use('dark_background')fig, ax = plt.subplots()L = 6x = np.linspace(0, L)ncolors = len(plt.rcParams['axes.prop_cycle'])shift = np.linspace(0, L, ncolors, endpoint=False)for s in shift: ax.plot(x, np.sin(x + s), 'o-')ax.set_xlabel('x-axis')ax.set_ylabel('y-axis')ax.s...
ggplot
ggplot样式表此示例演示了“ggplot”样式,该样式调整样式以模拟ggplot(R的流行绘图包)。 这些设置被无耻地从[1]窃取(经允许)。 [1] https://web.archive.org/web/20111215111010/http://www.huyng.com/archives/sane-color-scheme-for-matplotlib/691/ 123456789101112131415161718192021222324252627282930313233343536373839404142import numpy as npimport matplotlib.pyplot as pltplt.style.use('ggplot')# Fixing random state for reproducibilitynp.random.seed(19680801)fig, axes = plt.subplots(ncols=2, nrows=2)ax1, ax2, ax3, ax4 = axes.ravel()# scatter ...
plot_solarizedlight2
Solarized Light样式表这显示了一个“Solarized_Light”样式的示例,它试图复制以下样式: http://ethanschoonover.com/solarized https://github.com/jrnold/ggthemes http://pygal.org/en/stable/documentation/builtin_styles.html#light-solarized 并且: 使用调色板的所有8个重音 - 从蓝色开始 进行: 为条形图和堆积图创建Alpha值。 .33或.5 应用布局规则 123456789101112131415161718import matplotlib.pyplot as pltimport numpy as npx = np.linspace(0, 10)with plt.style.context('Solarize_Light2'): plt.plot(x, np.sin(x) + x + np.random.randn(50)) plt.plot(x, np.sin...
grayscale
灰度样式表此示例演示“灰度”样式表,该样式表将定义为rc参数的所有颜色更改为灰度。 但请注意,并非所有绘图元素都默认为rc参数定义的颜色。 12345678910111213141516171819202122232425262728293031import numpy as npimport matplotlib.pyplot as plt# Fixing random state for reproducibilitynp.random.seed(19680801)def color_cycle_example(ax): L = 6 x = np.linspace(0, L) ncolors = len(plt.rcParams['axes.prop_cycle']) shift = np.linspace(0, L, ncolors, endpoint=False) for s in shift: ax.plot(x, np.sin(x + s), 'o-')def image_and_p...
align_labels_demo
对齐标签使用 Figure.align_xlabels 和 Figure.align_ylabels 对齐xlabel和ylabel Figure.align_labels 包装了这两个函数。 注意,xlabel “XLabel11” 通常更接近x轴,“YLabel1 0” 将更接近其各自轴的y轴。 1234567891011121314151617181920212223import matplotlib.pyplot as pltimport numpy as npimport matplotlib.gridspec as gridspecfig = plt.figure(tight_layout=True)gs = gridspec.GridSpec(2, 2)ax = fig.add_subplot(gs[0, :])ax.plot(np.arange(0, 1e6, 1000))ax.set_ylabel('YLabel0')ax.set_xlabel('XLabel0')for i in range(2): ax = f...
axes_demo
轴线演示例如,使用plt.axes在主绘图轴中创建嵌入轴。 12345678910111213141516171819202122232425262728293031323334353637import matplotlib.pyplot as pltimport numpy as np# Fixing random state for reproducibilitynp.random.seed(19680801)# create some data to use for the plotdt = 0.001t = np.arange(0.0, 10.0, dt)r = np.exp(-t[:1000] / 0.05) # impulse responsex = np.random.randn(len(t))s = np.convolve(x, r)[:len(x)] * dt # colored noise# the main axes is subplot(111) by defaultplt.plot(t, s)plt.axis([0, 1, 1.1 * np.min...
style_sheets_reference
样式表参考此脚本演示了一组常见示例图上的不同可用样式表:散点图,图像,条形图,面片,线图和直方图, 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136import numpy as npimport matplotlib.pyplot as plt# Fixing random state for reproducibilitynp.random.seed(19680801)def pl...
axes_props
轴线属性您可以调整轴的刻度和网格属性。 12345678910111213import matplotlib.pyplot as pltimport numpy as npt = np.arange(0.0, 2.0, 0.01)s = np.sin(2 * np.pi * t)fig, ax = plt.subplots()ax.plot(t, s)ax.grid(True, linestyle='-.')ax.tick_params(labelcolor='r', labelsize='medium', width=3)plt.show() 下载这个示例 下载python源码: axes_props.py 下载Jupyter notebook: axes_props.ipynb
axes_margins
Axes.margins缩放粘性此示例中的第一个图显示了如何使用边距而不是set_xlim和set_ylim放大和缩小绘图。第二个图展示了某些方法和艺术家引入的边缘“粘性”的概念,以及如何有效地解决这个问题。 12345678910111213141516171819202122232425import numpy as npimport matplotlib.pyplot as pltdef f(t): return np.exp(-t) * np.cos(2*np.pi*t)t1 = np.arange(0.0, 3.0, 0.01)ax1 = plt.subplot(212)ax1.margins(0.05) # Default margin is 0.05, value 0 means fitax1.plot(t1, f(t1), 'k')ax2 = plt.subplot(221)ax2.margins(2, 2) # Values >0.0 zoom outax2.plot(t1, f(t1), ...
axes_zoom_effect
轴缩放效果 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116from matplotlib.transforms import ( Bbox, TransformedBbox, blended_transform_factory)from mpl_toolkits.axes_grid1.inset_locator import ( BboxPatch, BboxConnector, BboxConnectorPatch)def connect_bbox(bbox1, bbox2, loc1a, loc2a, lo...














