Scatter Plots in Matplotlib

import matplotlib.pyplot as plt

# Sample data
x = [1, 2, 3, 4, 5]
y = [10, 14, 19, 25, 30]

# Basic scatter plot
plt.scatter(x, y)

# Display the plot
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Basic Scatter Plot')
plt.show()
import matplotlib.pyplot as plt

# Sample data
x = [1, 2, 3, 4, 5]
y = [10, 14, 19, 25, 30]

# Scatter plot with custom marker colors
plt.scatter(x, y, c='red')

# Display the plot
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Scatter Plot with Custom Marker Color')
plt.show()
import matplotlib.pyplot as plt

# Sample data
x = [1, 2, 3, 4, 5]
y = [10, 14, 19, 25, 30]

# Scatter plot with custom marker size
plt.scatter(x, y, s=200)  # Size of markers set to 200

# Display the plot
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Scatter Plot with Custom Marker Size')
plt.show()
import matplotlib.pyplot as plt

# Sample data
x = [1, 2, 3, 4, 5]
y = [10, 14, 19, 25, 30]

# Scatter plot with custom marker style
plt.scatter(x, y, marker='^')  # Triangle-up markers

# Display the plot
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Scatter Plot with Custom Marker Style')
plt.show()
import matplotlib.pyplot as plt
import numpy as np

# Sample data - generating random data points using normal distribution
np.random.seed(0)
x = np.random.randn(1000)
y = np.random.randn(1000)

# Scatter plot with custom marker alpha
plt.scatter(x, y, alpha=0.5)  # Alpha set to 0.5 for partial transparency

# Display the plot
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Scatter Plot with Custom Marker Alpha')
plt.show()
import matplotlib.pyplot as plt
import numpy as np

# Sample data - generating random data points using normal distribution
np.random.seed(0)
x = np.random.randn(1000)
y = np.random.randn(1000)
colors = np.random.randn(1000)
sizes = np.random.randint(10, 101, size=1000)

# Scatter plot with multiple customizations
plt.scatter(x, y, c=colors, cmap="viridis", s=sizes, marker='o', alpha=0.5)

# Display the plot
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Scatter Plot with Multiple Customizations')
plt.show()
CTRL + ENTER to send