.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/path_effects/demo_cliprect.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_path_effects_demo_cliprect.py: ==================== ClipRect demo ==================== Adopted from seaborn's timeseries_facets example .. GENERATED FROM PYTHON SOURCE LINES 8-65 .. image-sg:: /examples/path_effects/images/sphx_glr_demo_cliprect_001.png :alt: demo cliprect :srcset: /examples/path_effects/images/sphx_glr_demo_cliprect_001.png :class: sphx-glr-single-img .. code-block:: Python # base on stacked-plots.py from Scientific Visualisation by N. P. Rougier import itertools import numpy as np import matplotlib.pyplot as plt from scipy.ndimage import gaussian_filter1d from mpl_visual_context.patheffects import ClipRect from mpl_visual_context.patheffects import StrokeColor, FillColor from SecretColors import Palette # from mpl_visual_context.patheffects import HLSaxb, ColorMatrix np.random.seed(1) fig, ax = plt.subplots(figsize=(8, 4), num=1, clear=True) X = np.linspace(0, 1, 500) Y0 = np.ones(len(X)) pe_clip = ClipRect(ax, left=X[325], right=X[424], coords="data") material = Palette("material") # [90, 80, ..., 10, 5] shades = itertools.chain(range(90, 10, -10), [5]) for i, shade in enumerate(shades): Y = Y0 + np.random.uniform(0, 1 / (i + 1), len(X)) Y = gaussian_filter1d(Y, 3) fc1 = material.get("yellow", shade=shade) fc2 = material.get("blue-gray", shade=shade) ax.fill_between( X, Y, Y0, edgecolor="black", linewidth=0.25, facecolor=fc1, # we first fill the path with fc2. Then we fill with original color byt # with ClipRect applied. path_effects = [FillColor(fc2) | StrokeColor("w"), pe_clip] ) Y0 = Y ax.axvline(X[325], color="black", linestyle="--") ax.axvline(X[424], color="black", linestyle="--") ax.set_xlim(0, 1) ax.set_xticks([]) ax.set_ylim(1, 3) ax.set_yticks([]) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.063 seconds) .. _sphx_glr_download_examples_path_effects_demo_cliprect.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: demo_cliprect.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: demo_cliprect.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: demo_cliprect.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_