We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import matplotlib.pyplot as plt import numpy as np
x = np.linspace(0, 10, 100) y = np.cos(x) z = np.sin(x) data = np.random.normal(0, 1, 1000)
fig, ax = plt.subplots(2, 2, figsize=(10, 10)) # 2x2 grid of subplots
ax[0, 0].plot(x, y, label='sin(x)') ax[0, 0].plot(x, z, label='cos(x)', linestyle='--') ax[0, 0].set_title('Line Plot') ax[0, 0].set_xlabel('x') ax[0, 0].set_ylabel('f(x)') ax[0, 0].legend()
ax[0, 1].scatter(x, y, color='red') ax[0, 1].set_title('Scatter Plot') ax[0, 1].set_xlabel('x') ax[0, 1].set_ylabel('sin(x)')
ax[1, 0].hist(data, bins=30, color='green', alpha=0.7) ax[1, 0].set_title('Histogram') ax[1, 0].set_xlabel('Value') ax[1, 0].set_ylabel('Frequency')
sizes = [25, 25, 25, 25] labels = ['North', 'South', 'East', 'West'] ax[1, 1].pie(sizes, labels=labels, autopct='%1.1f%%', startangle=90) ax[1, 1].set_title('Pie Chart') ax[1, 1].axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.
plt.tight_layout() plt.show()
The text was updated successfully, but these errors were encountered:
No branches or pull requests
import matplotlib.pyplot as plt
import numpy as np
Creating some data
x = np.linspace(0, 10, 100)
y = np.cos(x)
z = np.sin(x)
data = np.random.normal(0, 1, 1000)
Setting up the layout of the plots
fig, ax = plt.subplots(2, 2, figsize=(10, 10)) # 2x2 grid of subplots
Line plot
ax[0, 0].plot(x, y, label='sin(x)')
ax[0, 0].plot(x, z, label='cos(x)', linestyle='--')
ax[0, 0].set_title('Line Plot')
ax[0, 0].set_xlabel('x')
ax[0, 0].set_ylabel('f(x)')
ax[0, 0].legend()
Scatter plot
ax[0, 1].scatter(x, y, color='red')
ax[0, 1].set_title('Scatter Plot')
ax[0, 1].set_xlabel('x')
ax[0, 1].set_ylabel('sin(x)')
Histogram
ax[1, 0].hist(data, bins=30, color='green', alpha=0.7)
ax[1, 0].set_title('Histogram')
ax[1, 0].set_xlabel('Value')
ax[1, 0].set_ylabel('Frequency')
Pie chart
sizes = [25, 25, 25, 25]
labels = ['North', 'South', 'East', 'West']
ax[1, 1].pie(sizes, labels=labels, autopct='%1.1f%%', startangle=90)
ax[1, 1].set_title('Pie Chart')
ax[1, 1].axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.
plt.tight_layout()
plt.show()
The text was updated successfully, but these errors were encountered: