Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- import numpy as np
- x = np.arange(1,10)
- y = x ** 4
- a = np.arange(1,5)
- b = a * 100
- fig,axes = plt.subplots(nrows=2, ncols = 2, dpi = 200, figsize = (5,10))
- axes[0][0].plot(a,b)
- axes[1][0].plot(x,y)
- axes[0][0].set_xlabel("X label")
- axes[0][0].set_ylabel("Y label")
- axes[0][0].set_title("Title 1")
- fig.suptitle("Figure level",fontsize = 16)
- plt.tight_layout() # to solve a problem with space
- # fig.subplots_adjust(left =, right = , bottom = , top = , wspace = , hspace = ) # manual spacing
- ############################################################
- '''
- # Adjust the figure size
- plt.figure(figsize=(10,5))
- # Plot the histograms of X and Y next to each other
- plt.subplot(1,2,1)
- plt.hist(x = x, bins = 15)
- plt.title("X")
- plt.subplot(1,2,2)
- plt.hist(x = y, bins = 15)
- plt.title("Y")
- plt.show()
- #############################################################
- # Plot the data
- plt.figure(figsize=(10,10))
- plt.subplot(2,2,2)
- plt.scatter(x = x, y = y)
- plt.title("Joint Distribution of X and Y")
- # Plot the Marginal X Distribution
- plt.subplot(2,2,4)
- plt.hist(x = x, bins = 15)
- plt.title("Marginal Distribution of X")
- # Plot the Marginal Y Distribution
- plt.subplot(2,2,1)
- plt.hist(x = y, orientation = "horizontal", bins = 15)
- plt.title("Marginal Distribution of Y")
- # Show the plots
- plt.show()
- '''
Advertisement
Advertisement