.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_color_demo.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_auto_examples_plot_color_demo.py: ============================================================================== NicePlots Style Colors Demo ============================================================================== This script demonstrates colors available in each style. .. GENERATED FROM PYTHON SOURCE LINES 7-65 .. image-sg:: /auto_examples/images/sphx_glr_plot_color_demo_001.svg :alt: doumont-dark, doumont-light, james-dark, james-light :srcset: /auto_examples/images/sphx_glr_plot_color_demo_001.svg :class: sphx-glr-single-img .. code-block:: Python # ============================================================================== # Standard Python modules # ============================================================================== # ============================================================================== # External Python modules # ============================================================================== import matplotlib.pyplot as plt import niceplots # ============================================================================== # Extension modules # ============================================================================== # Get the style names from NicePlots styles = niceplots.get_available_styles() plt.style.use(niceplots.get_style("james-light")) fig, axs = plt.subplots(1, len(styles), figsize=(3 * len(styles), 8)) axs = axs.flatten() for i, style in enumerate(styles): with plt.style.context(niceplots.get_style(style)): ax = axs[i] colors = niceplots.get_colors() background = colors["Background"] for key in ["Axis", "Background", "Text", "Label"]: del colors[key] ax.set_title(style, pad=20.0) # Fill the background with the style's background color ax.fill_between([0, 1], [0, 0], [1, 1], color=background) # Swatch properties spacing = 0.05 y_spacing = spacing * 3 width = (1 - (len(colors) + 1) * spacing) / len(colors) # Plot the swatches for i_color, color in enumerate(colors.keys()): y_start = i_color * (spacing + width) + spacing y_end = width + y_start ax.fill_between([y_spacing, 1 - y_spacing], [y_start] * 2, [y_end] * 2, color=colors[color]) ax.text(0.5, (y_start + y_end) / 2, color, va="center", ha="center") ax.set_xlim([0, 1]) ax.set_ylim([0, 1]) ax.invert_yaxis() # Remove the spines and ticks ax.spines[["top", "bottom", "left", "right"]].set_visible(False) ax.set_xticks(()) ax.set_yticks(()) niceplots.save_figs(fig, "style_color_demo", ["png", "svg"]) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.778 seconds) .. _sphx_glr_download_auto_examples_plot_color_demo.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_color_demo.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_color_demo.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_color_demo.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_