{ "cells": [ { "cell_type": "markdown", "id": "46844364", "metadata": {}, "source": [ "# Cos Plot" ] }, { "cell_type": "code", "execution_count": null, "id": "a64ddd0e", "metadata": {}, "outputs": [], "source": [ "\"\"\"\n", " Form a cos(theta) plot in range 0 -> 4pi\n", "\"\"\"\n", "import math\n", "import matplotlib.pyplot as plt # Import the plot package as plt\n", "\n", "def main():\n", " plot_range = 4.0*math.pi # Range of plot\n", " plot_points = 100 # Number of point\n", " increment = plot_range/plot_points # Increment between points\n", "\n", " theta_data = [] # lists to hold the data\n", " cos_data = []\n", "\n", " for i in range(0,plot_points): # polulate the lists with theta, cos(theta)\n", " theta = increment*i # value of theta\n", " cos = math.cos(theta)\n", " theta_data.append(theta)\n", " cos_data.append(cos)\n", "\n", "\n", " plt.plot(theta_data,cos_data,\"g\") # Default plot in green\n", " plt.title(\"Plot of cosine\") # Add title/lables\n", " plt.xlabel(\"Angle theta\")\n", " plt.ylabel(\"Cos(theta)\")\n", " plt.show() # show the actual plot\n", "\n", "\n", "main()\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.9.7" } }, "nbformat": 4, "nbformat_minor": 5 }