1. Sade Plot (Matplotlib ile)¶

In [4]:
import matplotlib.pyplot as plt
import numpy as np

# Veri
x = np.linspace(0, 10, 100)
y = np.sin(x)
y2 = np.cos(x)

# Grafik
plt.figure(figsize=(10, 6))
plt.plot(x, y, label='sin(x)', linestyle='-', color='blue', linewidth=2, marker='o')
plt.plot(x, y2, label='cos(x)', linestyle='--', color='red', linewidth=2)

# Başlık ve etiketler
plt.title('Sine ve Cosine Fonksiyonları', fontsize=16)
plt.xlabel('x değeri', fontsize=12)
plt.ylabel('Fonksiyon değeri', fontsize=12)

# Denklemleri ekle (metin olarak)
plt.text(0.5, -0.5, r'$y = \sin(x)$', fontsize=12, color='blue')
plt.text(0.5, -0.4, r'$y = \cos(x)$', fontsize=12, color='red')

# Grid, legend, kayıt ve gösterim
plt.grid(True)
plt.legend()
plt.tight_layout()
plt.savefig("plot1_with_equation.png", dpi=300)
plt.show()

Histogram¶

In [6]:
import matplotlib.pyplot as plt
import numpy as np

# Rastgele veri
data = np.random.normal(loc=50, scale=10, size=1000)

# Histogram
plt.figure(figsize=(8, 5))
plt.hist(data, bins=30, color='green', edgecolor='black', alpha=0.7, density=True)

# Başlık ve etiketler
plt.title('Normal Dağılım Histogramı')
plt.xlabel('Değerler')
plt.ylabel('Frekans Yoğunluğu')

# Ortalama ve std çizgileri
plt.axvline(np.mean(data), color='red', linestyle='dashed', linewidth=2, label=f'Ortalama: {np.mean(data):.2f}')
plt.axvline(np.mean(data) + np.std(data), color='orange', linestyle='dotted', linewidth=2, label='1 Std Sapma')
plt.legend()
plt.tight_layout()

##plt.subplots_adjust(left=0.1, right=0.95, top=0.9, bottom=0.1, wspace=0.3, hspace=0.4) 
#Kenar boşluklarını manuel ayarlamak için kullanılır.
#Çoklu grafiklerde (subplots) çok kullanışlıdır.



plt.savefig("histogram.png", dpi=300)
plt.show()

SeaBorn¶

In [7]:
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt

# Veri seti (otomatik gelir)
df = sns.load_dataset("tips")

# Dağılım grafiği
plt.figure(figsize=(8, 5))
sns.scatterplot(data=df, x="total_bill", y="tip", hue="sex", style="smoker", size="size", palette="muted")
plt.title("Bahşiş vs Toplam Hesap")
plt.tight_layout()
plt.savefig("scatter_tips.png", dpi=300)
plt.show()

# Kutu grafiği
plt.figure(figsize=(8, 5))
sns.boxplot(data=df, x="day", y="total_bill", hue="sex")
plt.title("Günlere Göre Hesaplar")
plt.tight_layout()
plt.savefig("boxplot_tips.png", dpi=300)
plt.show()

3D Yüzey Grafiği (Surface Plot)¶

In [8]:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

# 3D veriler
x = np.linspace(-5, 5, 100)
y = np.linspace(-5, 5, 100)
X, Y = np.meshgrid(x, y)
Z = np.sin(np.sqrt(X**2 + Y**2))  # Fonksiyon

# Şekil ve 3D eksen oluştur
fig = plt.figure(figsize=(10, 7))
ax = fig.add_subplot(111, projection='3d')

# 3D yüzey grafiği
surf = ax.plot_surface(X, Y, Z, cmap='viridis', edgecolor='none', alpha=0.9)

# Başlık ve etiketler
ax.set_title("3D Yüzey Grafiği: $z = \sin(\sqrt{x^2 + y^2})$", fontsize=14)
ax.set_xlabel('X ekseni')
ax.set_ylabel('Y ekseni')
ax.set_zlabel('Z ekseni')

# Denklem açıklaması
ax.text2D(0.05, 0.95, r"$z = \sin(\sqrt{x^2 + y^2})$", transform=ax.transAxes, fontsize=12, color='black')

# Renk barı (legend gibi)
fig.colorbar(surf, shrink=0.5, aspect=10)

# Layout ayarı ve gösterim
plt.tight_layout()
plt.savefig("3d_surface_plot.png", dpi=300)
plt.show()