• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Jun 20th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
169.90 KB
1. {
2.  "cells": [
3.   {
4.    "cell_type": "code",
5.    "execution_count": 1,
7.    "outputs": [],
8.    "source": [
9.     "import numpy as np\n",
10.     "import matplotlib.pyplot as plt\n",
11.     "#importing numbers and visual libraries"
12.    ]
13.   },
14.   {
15.    "cell_type": "code",
16.    "execution_count": 45,
18.    "outputs": [
19.     {
20.      "data": {
22.       "text/plain": [
23.        "<Figure size 432x288 with 2 Axes>"
24.       ]
25.      },
27.       "needs_background": "light"
28.      },
29.      "output_type": "display_data"
30.     }
31.    ],
32.    "source": [
33.     "#creating figure and axes\n",
34.     "#1,1 = single plot area ; 1,2 = side by side two plots ; 2,1 = one below other subplots... \n",
35.     "\n",
36.     "# Create the figure and two axes (two rows, one column)\n",
37.     "fig, ax1 = plt.subplots(1, 1)\n",
38.     "\n",
39.     "# Share the x-axis for both the axes (ax1, ax2)\n",
40.     "ax2 = ax1.twinx()\n",
41.     "\n",
42.     "# Create a plot of y = sin(x) on the first row\n",
43.     "x1 = np.linspace(0, 5 * np.pi, 100)\n",
44.     "y1 = np.sin(x1)\n",
45.     "ax1.plot(x1, y1)\n",
46.     "\n",
47.     "# Create a plot of y = cos(x) on the second row\n",
48.     "x2 = np.linspace(0, 5 * np.pi, 100)\n",
49.     "y2 = np.cos(x2)\n",
50.     "ax2.plot(x2, y2)\n",
51.     "\n",
52.     "# Save the figure\n",
53.     "plt.savefig('sin_cos_2.png')\n"
54.    ]
55.   },
56.   {
57.    "cell_type": "code",
58.    "execution_count": 46,
60.    "outputs": [
61.     {
62.      "data": {
64.       "text/plain": [
65.        "<Figure size 432x288 with 2 Axes>"
66.       ]
67.      },
69.       "needs_background": "light"
70.      },
71.      "output_type": "display_data"
72.     }
73.    ],
74.    "source": [
75.     "# Create the figure and two axes (two rows, one column)\n",
76.     "fig, ax1 = plt.subplots(1, 1)\n",
77.     "\n",
78.     "# Share the x-axis for both the axes (ax1, ax2)\n",
79.     "ax2 = ax1.twinx()\n",
80.     "\n",
81.     "# Create a plot of y = sin(x) on the first row\n",
82.     "x1 = np.linspace(0, 4 * np.pi, 100)\n",
83.     "y1 = np.sin(x1)\n",
84.     "function1 = ax1.plot(x1, y1, label='Sine')\n",
85.     "\n",
86.     "# Create a plot of y = cos(x) on the second row\n",
87.     "x2 = np.linspace(0, 4 * np.pi, 100)\n",
88.     "y2 = np.cos(x2)\n",
89.     "function2 = ax2.plot(x2, y2, label='Cosine')\n",
90.     "\n",
91.     "# Create the legend by first fetching the labels from the functions\n",
92.     "functions = function1 + function2\n",
93.     "labels = [f.get_label() for f in functions]\n",
94.     "plt.legend(functions, labels, loc=2)\n",
95.     "\n",
96.     "# Save the figure\n",
97.     "plt.savefig('sin_cos_3.png')\n"
98.    ]
99.   },
100.   {
101.    "cell_type": "code",
102.    "execution_count": 56,
104.    "outputs": [
105.     {
106.      "data": {
108.       "text/plain": [
109.        "<Figure size 432x288 with 2 Axes>"
110.       ]
111.      },
113.       "needs_background": "light"
114.      },
115.      "output_type": "display_data"
116.     }
117.    ],
118.    "source": [
119.     "#Adding colors or icons - x, o are for icons where as r=red, b=blue, y=yellow\n",
120.     "\n",
121.     "# Create the figure and two axes (two rows, one column)\n",
122.     "fig, ax1 = plt.subplots(1, 1)\n",
123.     "\n",
124.     "# Share the x-axis for both the axes (ax1, ax2)\n",
125.     "ax2 = ax1.twinx()\n",
126.     "\n",
127.     "# Create a plot of y = sin(x) on the first row\n",
128.     "x1 = np.linspace(0, 4 * np.pi, 100)\n",
129.     "y1 = np.sin(x1)\n",
130.     "function1 = ax1.plot(x1, y1,'m', label='Sine')\n",
131.     "\n",
132.     "# Create a plot of y = cos(x) on the second row\n",
133.     "x2 = np.linspace(0, 4 * np.pi, 100)\n",
134.     "y2 = np.cos(x2)\n",
135.     "function2 = ax2.plot(x2, y2, 'c',label='Cosine')\n",
136.     "\n",
137.     "# Create the legend by first fetching the labels from the functions\n",
138.     "functions = function1 + function2\n",
139.     "labels = [f.get_label() for f in functions]\n",
140.     "plt.legend(functions, labels, loc=2)\n",
141.     "\n",
142.     "# Save the figure\n",
143.     "plt.savefig('sin_cos_4.png')\n"
144.    ]
145.   },
146.   {
147.    "cell_type": "code",
148.    "execution_count": 66,
150.    "outputs": [
151.     {
152.      "data": {
154.       "text/plain": [
155.        "<Figure size 432x288 with 2 Axes>"
156.       ]
157.      },
159.       "needs_background": "light"
160.      },
161.      "output_type": "display_data"
162.     }
163.    ],
164.    "source": [
165.     "#Adding Title to a graph\n",
166.     "\n",
167.     "\n",
168.     "# Create the figure and two axes (two rows, one column)\n",
169.     "fig, ax1 = plt.subplots(1, 1)\n",
170.     "\n",
171.     "# Share the x-axis for both the axes (ax1, ax2)\n",
172.     "ax2 = ax1.twinx()\n",
173.     "\n",
174.     "# Create a plot of y = sin(x) on the first row\n",
175.     "x1 = np.linspace(0, 4 * np.pi, 100)\n",
176.     "y1 = np.sin(x1)\n",
177.     "function1 = ax1.plot(x1, y1,'m', label='Sine')\n",
178.     "\n",
179.     "# Create a plot of y = cos(x) on the second row\n",
180.     "x2 = np.linspace(0, 4 * np.pi, 100)\n",
181.     "y2 = np.cos(x2)\n",
182.     "function2 = ax2.plot(x2, y2, 'c',label='Cosine')\n",
183.     "\n",
184.     "# Create the legend by first fetching the labels from the functions\n",
185.     "functions = function1 + function2\n",
186.     "labels = [f.get_label() for f in functions]\n",
187.     "plt.legend(functions, labels, loc=3)\n",
188.     "\n",
189.     "#adding X and Y axes names\n",
190.     "ax1.set_xlabel('\$X\$')\n",
191.     "ax1.set_ylabel('\$Y1\$')\n",
192.     "ax2.set_ylabel('\$Y2\$')\n",
193.     "\n",
195.     "plt.title('Sine and Cosine Chart')\n",
196.     "\n",
197.     "# Adjust the figure such that all rendering components fit inside the figure\n",
198.     "plt.tight_layout()\n",
199.     "\n",
200.     "# Save the figure\n",
201.     "plt.savefig('sin_cos_5.png')\n",
202.     "\n"
203.    ]
204.   },
205.   {
206.    "cell_type": "code",
207.    "execution_count": 67,
209.    "outputs": [],
210.    "source": []
211.   },
212.   {
213.    "cell_type": "code",
214.    "execution_count": 70,
216.    "outputs": [
217.     {
218.      "data": {
220.       "text/plain": [
221.        "<Figure size 432x288 with 2 Axes>"
222.       ]
223.      },
225.       "needs_background": "light"
226.      },
227.      "output_type": "display_data"
228.     }
229.    ],
230.    "source": [
231.     "import numpy as np\n",
232.     "import matplotlib.pyplot as plt\n",
233.     "# Import another rendering engine\n",
234.     "import seaborn as sns\n",
235.     "\n",
236.     "# Create the figure and two axes (two rows, one column)\n",
237.     "fig, ax1 = plt.subplots(1, 1)\n",
238.     "\n",
239.     "# Share the x-axis for both the axes (ax1, ax2)\n",
240.     "ax2 = ax1.twinx()\n",
241.     "\n",
242.     "# Create a plot of y = sin(x) on the first row\n",
243.     "x1 = np.linspace(0, 4 * np.pi, 100)\n",
244.     "y1 = np.sin(x1)\n",
245.     "# Add a label for the legend and make it blue\n",
246.     "function1 = ax1.plot(x1, y1, 'b', label='Sine')\n",
247.     "\n",
248.     "# Create a plot of y = cos(x) on the second row\n",
249.     "x2 = np.linspace(0, 4 * np.pi, 100)\n",
250.     "y2 = np.cos(x2)\n",
251.     "# Add a label for the legend and make it red\n",
252.     "function2 = ax2.plot(x2, y2, 'r', label='Cosine')\n",
253.     "\n",
254.     "# Create the legend by first fetching the labels from the functions\n",
255.     "functions = function1 + function2\n",
256.     "labels = [f.get_label() for f in functions]\n",
257.     "plt.legend(functions, labels, loc=0)\n",
258.     "\n",
259.     "# Add x-label (only one, since it is shared) and the y-labels\n",
260.     "ax1.set_xlabel('\$x\$')\n",
261.     "ax1.set_ylabel('\$y_1\$')\n",
262.     "ax2.set_ylabel('\$y_2\$')\n",
263.     "\n",
265.     "plt.title('Sine and Cosine')\n",
266.     "\n",
267.     "# Adjust the figure such that all rendering components fit inside the figure\n",
268.     "plt.tight_layout()\n",
269.     "\n",
270.     "# Save the figure\n",
271.     "plt.savefig('sin_cos_6.png')"
272.    ]
273.   },
274.   {
275.    "cell_type": "code",
276.    "execution_count": null,
278.    "outputs": [],
279.    "source": []
280.   }
281.  ],
283.   "kernelspec": {
284.    "display_name": "Python 3",
285.    "language": "python",
286.    "name": "python3"
287.   },
288.   "language_info": {
289.    "codemirror_mode": {
290.     "name": "ipython",
291.     "version": 3
292.    },
293.    "file_extension": ".py",
294.    "mimetype": "text/x-python",
295.    "name": "python",
296.    "nbconvert_exporter": "python",
297.    "pygments_lexer": "ipython3",
298.    "version": "3.6.8"
299.   }
300.  },
301.  "nbformat": 4,
302.  "nbformat_minor": 2
303. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top