اذهب إلى المحتوى
  • 0

وضع عنوان واحد رئيسي فوق كل ال subplots في Matplotlib | بايثون

Ali Ismael

السؤال

قمت برسم الأشكال ال 4 التالية وأريد وضع عنوان عام لهذه ال subplots فكيف نقوم بذلك؟

# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
# First create some toy data:
x = np.linspace(0, 1.5 * np.pi, 100)
y = np.sin(x**2)+np.cos(x**2)
fig, axs = plt.subplots(2, 2,
						subplot_kw = dict(polar = True))
axs[0, 0].plot(x, y)
axs[1, 1].scatter(x, y)
plt.show()


index.png.5b96bf10d215fc187ca72918c0d0a95e.png
 

تم التعديل في بواسطة Ali Ismael
رابط هذا التعليق
شارك على الشبكات الإجتماعية

Recommended Posts

  • 1

للقيام بذلك نستخدم الدالة suptitle:

matplotlib.pyplot.suptitle(t,x,y,horizontalalignment,fontsize, **kwargs)
# الوسيط الأول يمثل النص المطلوب إضافته
# x , y للتحكم بموقع النص
# horizontalalignment لتغيير موضع النص  
# ويأخذ القيم التالية
# center: الحالة الافتراضية
# left: على يسار الشكل
# right: على يمينه
# fontsize للتحكم بحجم الخط

وبالتالي لتنفيذ ماتريده:

# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
# First create some toy data:
x = np.linspace(0, 1.5 * np.pi, 100)
y = np.sin(x**2)+np.cos(x**2)
fig, axs = plt.subplots(2, 2,
						subplot_kw = dict(polar = True))
axs[0, 0].plot(x, y)
axs[1, 1].scatter(x, y)
# هنا نستخدم هذه الدالة 
fig.suptitle('Hsoub',color="red")
plt.show()

والخرج:
1.png.bf7fa0e1174e07a41d0bd738e77d94ba.png

تم التعديل في بواسطة Ali Haidar Ahmad
رابط هذا التعليق
شارك على الشبكات الإجتماعية

  • -1

بعد انشاء الـ subplot 

ax = plt.subplot(...)

يمكن تغيير العنوان للـ subplot من الخاصية title عن طريق استدعاء الدالة set_text كالتالي 

ax.title.set_text("title")

يصبح المثال لديك كالتالي

axs[0, 0].title.set_text('Title 1')
axs[1, 0].title.set_text('Title 2')
axs[0, 1].title.set_text('Title 3')
axs[1, 1].title.set_text('Title 4')

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...