#!/usr/bin/env python # coding: utf-8 # ### Multiplt Plots into One Figure # There are many ways to do, we will see two methods - # a. Predefined No of Subplots # b. Adding No of Subplots # In[2]: # import import matplotlib.pyplot as plt import numpy as np get_ipython().run_line_magic('matplotlib', 'inline') # In[60]: # generating some data points X = np.linspace(-np.pi, np.pi, 35, endpoint=True) C, S= np.cos(X), np.sin(X) # #### Predefined No of Subplots = 1 row, 3 plot # In[64]: fig = plt.figure() f, axes = plt.subplots(1, 3) # 1 row and 3 columns # Using subplot axes[0].plot(X, C, '.') axes[0].set_ylabel('Cos') axes[1].plot(X, S, '-') axes[1].set_ylabel('Sin') axes[2].plot(X, S+0.1, 'o') axes[2].set_ylabel('MSin') # #### Adding no of plots # In[65]: plt.clf() # clear the plot # In[77]: fig = plt.figure() ax=fig.add_subplot(131) ax.plot(X, C, '.') ax=fig.add_subplot(133) ax.plot(X, S) # #### Using this way you can allot different size to plots # In[78]: plt.clf() # **Chossing Plotting CoOrdinates** # In[96]: fig = plt.figure() ax=fig.add_subplot(331) # plot coordinates - 1st of (3,3) plot grid ax.plot(X, C, '.') ax=fig.add_subplot(323) # plot coordinates - 3rd of (3,2) plot grid ax.plot(X, S+0.2) ax=fig.add_subplot(324) # plot coordinates - 4th of (3,2) plot grid ax.plot(X, S) ax=fig.add_subplot(338) # plot coordinates - 8th of (3,3) plot grid ax.plot(X, S) # **Another Example** # In[97]: plt.clf() fig = plt.figure() ax=fig.add_subplot(431) # plot coordinates - 1st of (4,3) plot grid ax.plot(X, C, '.') ax=fig.add_subplot(423) # plot coordinates - 3rd of (4,2) plot grid ax.plot(X, S+0.2) ax=fig.add_subplot(424) # plot coordinates - 4th of (4,2) plot grid ax.plot(X, S) ax=fig.add_subplot(438) # plot coordinates - 8th of (4,3) plot grid ax.plot(X, S) ax=fig.add_subplot(234) # plot coordinates - 4th of (2,3) plot grid ax.plot(X, C*0.4) # **Adding diffrent plots into one subplot** # In[137]: #plt.clf() plt.plot(X, C) plt.show() # In[138]: plt.plot(X, S) plt.show() # In[134]: plt.plot(X, S*0.3) # In[121]: 20.8 % 10 # In[130]: a = [1,2,3,4] b = [4,7,3,4] list(zip(a,b)) # In[131]: a == b # In[ ]: