{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Demo running Python in Jupyter notebook\n", "In this document, we explore application of Jupyter notebook for running Python scripts." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Import package" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Generate data and perform calculations" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "random_numbers = np.random.rand(100)\n", "mean_value = np.mean(random_numbers)\n", "\n", "print(\"Random numbers:\", random_numbers)\n", "print(\"Mean value:\", mean_value)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Generate plots" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Create a plot\n", "plt.figure(figsize=(10, 6))\n", "plt.plot(random_numbers, marker='o', linestyle='-', color='b', label='Random Numbers')\n", "plt.axhline(y=mean_value, color='r', linestyle='--', label=f'Mean Value: {mean_value:.2f}')\n", "plt.title('Plot of 100 Random Numbers')\n", "plt.xlabel('Index')\n", "plt.ylabel('Value')\n", "plt.legend()\n", "plt.grid(True)\n", "\n", "\n", "# Display the plot\n", "plt.show()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.8" } }, "nbformat": 4, "nbformat_minor": 2 }