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

تغيير لون الخلفية Background باستخدام seaborn في بايثون

إياد أحمد

السؤال

لدي الكود التالي الذي يعبر عن مخطط بياني:

import seaborn as sns
import matplotlib.pyplot as plt
# loading dataset
data = sns.load_dataset("iris")
# draw lineplot
sns.lineplot(x="sepal_length", y="sepal_width", data=data)
plt.show()

لكن خلفية الشكل تكون بيضاء، وأريد أن يتم تغييرها، لذا كيف نقوم بذلك؟

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

Recommended Posts

  • 1

يمكنك تغييرها من خلال استخدام الوسيط rc ضمن الدالة set حيث نمرر له قاموساً مفاتيحه هي axes.facecolor وقيمته تمثل لون ال axes (أي لون المكان الذي يتم فيه رسم الشكل البياني) و figure.facecolor وقيمته تمثل لون ال figure (الحاوية الكلية).

import seaborn as sns
import matplotlib.pyplot as plt
# loading dataset
data = sns.load_dataset("iris")
# draw lineplot
sns.lineplot(x="sepal_length", y="sepal_width", data=data)
# هنا سنجعل اللون أحمر للمحور وأزرق للحاوية
sns.set(rc={'axes.facecolor':'red', 'figure.facecolor':'blue'})
plt.show()

الخرج:
61c34fd9124ec_.png.53b1a4e9e56f9ccdde14672757943b3f.png

حل آخر من خلال الدالة set_style التي تأخذ القيم التالية ticks - white - dark - darkgrid - whitegrid:

import seaborn as sns
import matplotlib.pyplot as plt
# loading dataset
data = sns.load_dataset("iris")
# draw lineplot
sns.lineplot(x="sepal_length", y="sepal_width", data=data)
sns.set_style("dark")
plt.show()

الخرج:
61c350a0b78cf_(1).png.d9a26cd8ddcc300ba5f3a8ba7cace982.png

 

 

 

 

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

  • 0

يمكنك كذلك استخدام الدالة facet.set مع استخدام المعامل axis_bgcolor وذلك لظبط ألوان الخلفية كالتالي:

import seaborn as sns
import matplotlib.pyplot as plt
# loading dataset
data = sns.load_dataset("iris")
# draw lineplot
facet = sns.lineplot(x="sepal_length", y="sepal_width", data=data)
facet.set(axis_bgcolor='k')
plt.show()

أو استخدام الدالة sns.set(style = color)  لضبط لون الخلفية بسهولة كالتالي:

import seaborn as sns
import matplotlib.pyplot as plt
# loading dataset
data = sns.load_dataset("iris")
# ضبط اللون
sns.set(style = "darkgrid")
facet = sns.lineplot(x="sepal_length", y="sepal_width", data=data)

plt.show()

وتظهر كالتالي:

61c895377b304_Figure2021-12-26181442.png.b181356b921f036c7a06058996c42ec4.png

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

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

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

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

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   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.

  • إعلانات

  • تابعنا على



×
×
  • أضف...