.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "extensions/sphinx-gallery/plot_05_output.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_05_output.py: Console Output ====================== This example demonstrates how sphinx-gallery captures and displays stdout output from ``print()`` statements and other console output. .. note:: All printed output is captured and rendered in the generated documentation, making it easy to show computation results. .. GENERATED FROM PYTHON SOURCE LINES 13-16 .. code-block:: Python import matplotlib.pyplot as plt .. GENERATED FROM PYTHON SOURCE LINES 17-21 Basic Print Statements ---------------------- Simple print output is captured and displayed in a styled output block. .. GENERATED FROM PYTHON SOURCE LINES 21-25 .. code-block:: Python print("Hello from sphinx-gallery!") print("This output is captured and displayed.") .. rst-class:: sphx-glr-script-out .. code-block:: none Hello from sphinx-gallery! This output is captured and displayed. .. GENERATED FROM PYTHON SOURCE LINES 26-30 Formatted Output ---------------- More complex formatted output with multiple lines. .. GENERATED FROM PYTHON SOURCE LINES 30-44 .. code-block:: Python print("=" * 50) print("Formatted Report") print("=" * 50) data = {"apples": 12, "oranges": 8, "bananas": 15, "grapes": 23} print("\nFruit Inventory:") print("-" * 30) for fruit, count in data.items(): print(f" {fruit.capitalize():12} : {count:3d} items") print("-" * 30) print(f" {'Total':12} : {sum(data.values()):3d} items") .. rst-class:: sphx-glr-script-out .. code-block:: none ================================================== Formatted Report ================================================== Fruit Inventory: ------------------------------ Apples : 12 items Oranges : 8 items Bananas : 15 items Grapes : 23 items ------------------------------ Total : 58 items .. GENERATED FROM PYTHON SOURCE LINES 45-49 Numeric Computations -------------------- Output from calculations and data processing. .. GENERATED FROM PYTHON SOURCE LINES 49-60 .. code-block:: Python import numpy as np arr = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) print(f"Array: {arr}") print(f"Sum: {arr.sum()}") print(f"Mean: {arr.mean():.2f}") print(f"Std: {arr.std():.2f}") print(f"Min: {arr.min()}, Max: {arr.max()}") .. rst-class:: sphx-glr-script-out .. code-block:: none Array: [ 1 2 3 4 5 6 7 8 9 10] Sum: 55 Mean: 5.50 Std: 2.87 Min: 1, Max: 10 .. GENERATED FROM PYTHON SOURCE LINES 61-65 Multi-line and Tabular Output ----------------------------- Displaying structured data in table format. .. GENERATED FROM PYTHON SOURCE LINES 65-79 .. code-block:: Python headers = ["Name", "Age", "City"] rows = [ ["Alice", 28, "New York"], ["Bob", 34, "Los Angeles"], ["Charlie", 22, "Chicago"], ] # Print as table print(f"\n{headers[0]:<10} {headers[1]:<6} {headers[2]:<15}") print("-" * 35) for row in rows: print(f"{row[0]:<10} {row[1]:<6} {row[2]:<15}") .. rst-class:: sphx-glr-script-out .. code-block:: none Name Age City ----------------------------------- Alice 28 New York Bob 34 Los Angeles Charlie 22 Chicago .. GENERATED FROM PYTHON SOURCE LINES 80-84 Return Values ------------- The last expression in a code block is also displayed if it has a value. .. GENERATED FROM PYTHON SOURCE LINES 84-88 .. code-block:: Python result = {"status": "success", "count": 42, "items": ["a", "b", "c"]} result .. rst-class:: sphx-glr-script-out .. code-block:: none {'status': 'success', 'count': 42, 'items': ['a', 'b', 'c']} .. GENERATED FROM PYTHON SOURCE LINES 89-93 Minimal Plot ------------ A simple plot to ensure this example runs (files must start with plot\_). .. GENERATED FROM PYTHON SOURCE LINES 93-99 .. code-block:: Python plt.figure(figsize=(4, 2)) plt.text(0.5, 0.5, "Output Demo", ha="center", va="center", fontsize=16) plt.axis("off") plt.tight_layout() plt.show() .. image-sg:: /extensions/sphinx-gallery/images/sphx_glr_plot_05_output_001.png :alt: plot 05 output :srcset: /extensions/sphinx-gallery/images/sphx_glr_plot_05_output_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.018 seconds) .. _sphx_glr_download_extensions_sphinx-gallery_plot_05_output.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_05_output.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_05_output.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_05_output.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_