Responsive Navbar with Google Search
☰ Menu
Home
Python
LaTeX
GNUPlot
Arduino
Feedback
Contact Us
Plotting in Python: Subplot, Multiplot
Plotting in Python
Basic Plot and formatting
Subplot, Multiplot
Colormaps in Plots
Bar Plot
Pie Chart
Histogram
Quiver plot to show Vector Fields
Stream plot to Visualize Flow Data
Polar, Parametric Plot
Contour Plot
3D Plot
Density Plot
Animated Plot
Miscellaneous
Subplot, Multiplot: Program 1
Line and Scatter Plot in one Figure
import matplotlib.pyplot as plt import numpy as np x = np.linspace(0, 10, 100) y1 = np.sin(x) y2 = np.cos(x) fig, axs = plt.subplots(2, 1, figsize=(12, 10)) axs[0].plot(x, y1, 'b-', label='sin(x)') axs[0].set_title('Line Plot') axs[0].set_xlabel('x') axs[0].set_ylabel('sin(x)') axs[0].grid(True) axs[1].scatter(x, y2, color='r', label='cos(x)') axs[1].set_title('Scatter Plot') axs[1].set_xlabel('x') axs[1].set_ylabel('cos(x)') axs[1].grid(True) plt.savefig('subplot_1.png') plt.show()
Run Code
Output 1
Subplot, Multiplot: Program 2
Multiple plots in one Figure
import matplotlib.pyplot as plt import numpy as np x = np.linspace(0, 10, 100) y1 = np.sin(x) y2 = np.cos(x) y3 = np.tan(x) fig, axs = plt.subplots(3, 1, figsize=(6, 15)) axs[0].plot(x, y1, 'b-') axs[0].set_title('sin(x)') axs[0].set_xlabel('x') axs[0].set_ylabel('sin(x)') axs[0].grid(True) axs[1].plot(x, y2, 'r-') axs[1].set_title('cos(x)') axs[1].set_xlabel('x') axs[1].set_ylabel('cos(x)') axs[1].grid(True) axs[2].plot(x, y3, 'g-') axs[2].set_title('tan(x)') axs[2].set_xlabel('x') axs[2].set_ylabel('tan(x)') axs[2].grid(True) plt.savefig('subplot_2.png') plt.show()
Run Code
Output 2