Skip to content
New issue

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

Why is my graphs incorrect? #6

Open
DanjieTang opened this issue Apr 18, 2024 · 0 comments
Open

Why is my graphs incorrect? #6

DanjieTang opened this issue Apr 18, 2024 · 0 comments

Comments

@DanjieTang
Copy link
Owner

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant