.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "extensions/sphinx-gallery/plot_04_styled.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_extensions_sphinx-gallery_plot_04_styled.py: Styled Visualizations ===================== This example showcases different plot styles and annotations. It demonstrates how sphinx-gallery captures complex matplotlib figures. .. seealso:: - :doc:`plot_01_basic` for a simpler example - :doc:`plot_03_subplots` for subplot layouts .. GENERATED FROM PYTHON SOURCE LINES 13-19 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np # sphinx_gallery_thumbnail_number = 2 .. GENERATED FROM PYTHON SOURCE LINES 20-24 Area Plot with Gradient ----------------------- A filled area plot showing data distribution over time. .. GENERATED FROM PYTHON SOURCE LINES 24-39 .. code-block:: Python x = np.linspace(0, 10, 100) y1 = np.sin(x) + 2 y2 = np.sin(x + np.pi / 4) + 2 plt.figure(figsize=(10, 5)) plt.fill_between(x, 0, y1, alpha=0.5, label="Series A") plt.fill_between(x, 0, y2, alpha=0.5, label="Series B") plt.xlabel("Time") plt.ylabel("Value") plt.title("Stacked Area Plot") plt.legend() plt.tight_layout() plt.show() .. image-sg:: /extensions/sphinx-gallery/images/sphx_glr_plot_04_styled_001.png :alt: Stacked Area Plot :srcset: /extensions/sphinx-gallery/images/sphx_glr_plot_04_styled_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 40-46 Annotated Plot -------------- This figure includes text annotations and markers pointing to specific features. The ``sphinx_gallery_thumbnail_number = 2`` directive at the top makes this the gallery thumbnail. .. GENERATED FROM PYTHON SOURCE LINES 46-85 .. code-block:: Python x = np.linspace(0, 2 * np.pi, 100) y = np.sin(x) fig, ax = plt.subplots(figsize=(10, 5)) ax.plot(x, y, "b-", linewidth=2) # Mark maximum and minimum max_idx = np.argmax(y) min_idx = np.argmin(y) ax.annotate( "Maximum", xy=(x[max_idx], y[max_idx]), xytext=(x[max_idx] + 0.5, y[max_idx] + 0.3), fontsize=12, arrowprops=dict(arrowstyle="->", color="green"), color="green", ) ax.annotate( "Minimum", xy=(x[min_idx], y[min_idx]), xytext=(x[min_idx] + 0.5, y[min_idx] - 0.3), fontsize=12, arrowprops=dict(arrowstyle="->", color="red"), color="red", ) ax.scatter([x[max_idx], x[min_idx]], [y[max_idx], y[min_idx]], c=["green", "red"], s=100, zorder=5) ax.set_xlabel("x") ax.set_ylabel("y") ax.set_title("Sine Wave with Annotations") ax.grid(True, alpha=0.3) plt.tight_layout() plt.show() .. image-sg:: /extensions/sphinx-gallery/images/sphx_glr_plot_04_styled_002.png :alt: Sine Wave with Annotations :srcset: /extensions/sphinx-gallery/images/sphx_glr_plot_04_styled_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 86-90 Heatmap ------- A 2D heatmap visualization with a colorbar. .. GENERATED FROM PYTHON SOURCE LINES 90-101 .. code-block:: Python data = np.random.rand(8, 8) plt.figure(figsize=(8, 6)) plt.imshow(data, cmap="coolwarm", aspect="auto") plt.colorbar(label="Intensity") plt.xlabel("Column") plt.ylabel("Row") plt.title("Random Heatmap") plt.tight_layout() plt.show() .. image-sg:: /extensions/sphinx-gallery/images/sphx_glr_plot_04_styled_003.png :alt: Random Heatmap :srcset: /extensions/sphinx-gallery/images/sphx_glr_plot_04_styled_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.277 seconds) .. _sphx_glr_download_extensions_sphinx-gallery_plot_04_styled.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_04_styled.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_04_styled.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_04_styled.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_