Line plot
import matplotlib.pyplot as plt
# Data for the plot
x = [1, 2, 3, 4, 5]
y = [2, 3, 5, 7, 11]
# Create the line plot
plt.plot(x, y, marker='o')
# Adding labels and title
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Simple Line Plot')
# Add grid and legend
plt.grid(True)
# Display the plot
plt.show()
Bar Plot
import matplotlib.pyplot as plt
# Data for the bar chart
categories = ['A', 'B', 'C', 'D', 'E']
values = [5, 7, 3, 8, 6]
# Create the bar chart
plt.bar(categories, values)
# Adding labels and title
plt.xlabel('Categories')
plt.ylabel('Values')
plt.title('Simple Bar Chart')
# Add grid and legend
plt.grid(axis='y')
# Display the plot
plt.show()
Pie Chart
import matplotlib.pyplot as plt
# Data for the pie chart
labels = ['Category A', 'Category B', 'Category C', 'Category D']
sizes = [30, 45, 15, 10] # Percentage or proportional values
colors = ['gold', 'lightblue', 'lightgreen', 'salmon']
# Create the pie chart
plt.pie(sizes, labels=labels, colors=colors, autopct='%1.1f%%')
# Adding title
plt.title('Simple Pie Chart')
# Display the plot
plt.show()
Histogram
import matplotlib.pyplot as plt
# Data for the histogram
data = [7, 8, 5, 6, 8, 7, 9, 10, 6, 5, 7, 8, 10, 9, 6, 5, 7, 9]
# Create the histogram
plt.hist(data, bins=5, edgecolor='black')
# Adding labels and title
plt.xlabel('Value Ranges')
plt.ylabel('Frequency')
plt.title('Simple Histogram')
# Add grid
plt.grid(axis='y')
# Display the plot
plt.show()
Box plot
import matplotlib.pyplot as plt
# Data for the box plot
data = [7, 8, 5, 6, 8, 7, 9, 10, 6, 5, 7, 8, 10, 9, 6, 5, 7, 9]
# Create the box plot
plt.boxplot(data, patch_artist=True, boxprops=dict(facecolor='lightblue'))
# Adding labels and title
plt.xlabel('Dataset')
plt.ylabel('Values')
plt.title('Simple Box Plot')
# Display the plot
plt.show()
ScatterPlot
import matplotlib.pyplot as plt
# Data for the scatter plot
x = [1, 2, 3, 4, 5, 6]
y = [2, 4, 1, 8, 7, 5]
sizes = [50, 100, 200, 300, 400, 500] # Sizes of points
# Create the scatter plot
plt.scatter(x, y, s=sizes)
# Adding labels and title
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Simple Scatter Plot')
# Add grid
plt.grid(True)
# Display the plot
plt.show()
heatmap
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
# Data for the heatmap
data = np.array([[3, 5, 7],
[2, 8, 6],
[4, 9, 1]])
# Create the heatmap
sns.heatmap(data, annot=True, cmap='coolwarm', linewidths=0.5, linecolor='black', cbar=True)
# Adding labels and title
plt.xlabel('Columns')
plt.ylabel('Rows')
plt.title('Heatmap with Seaborn')
# Display the plot
plt.show()