PYTHON Tutorial

العمل مع عدة رسوم بيانية

المفاهيم الأساسية:

  • Subplots: رسوم بيانية متعددة داخل رسم بياني واحد.
  • Multiple figures: رسوم بيانية متعددة في وثيقة واحدة.
  • Grid spec: نظام لوضع رسوم بيانية متعددة في تخطيط معين.

الخطوات العملية:

  • استيراد مكتبة Matplotlib:
import matplotlib.pyplot as plt
  • إنشاء رسم بياني فارغ:
fig, axes = plt.subplots(nrows=2, ncols=2)
  • إنشاء Subplots:
# رسم بياني 1
axes[0, 0].plot(x1, y1)

# رسم بياني 2
axes[0, 1].plot(x2, y2)

# رسم بياني 3
axes[1, 0].plot(x3, y3)

# رسم بياني 4
axes[1, 1].plot(x4, y4)
  • تعيين عناوين المحاور ووضع العلامات:
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Multiple Plots')
  • عرض الرسوم البيانية:
plt.show()

استخدام Grid spec:

  • استيراد GridSpec من matplotlib.gridspec:
from matplotlib.gridspec import GridSpec
  • إنشاء رسم بياني باستخدام GridSpec:
fig = plt.figure()
gs = GridSpec(2, 2)

# رسم بياني 1
ax1 = fig.add_subplot(gs[0, 0])
ax1.plot(x1, y1)

# رسم بياني 2
ax2 = fig.add_subplot(gs[0, 1])
ax2.plot(x2, y2)

# رسم بياني 3
ax3 = fig.add_subplot(gs[1, 0])
ax3.plot(x3, y3)

# رسم بياني 4
ax4 = fig.add_subplot(gs[1, 1])
ax4.plot(x4, y4)