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

تغيير لون المحور axis باستخدام Matplotlib في بايثون

Ali Ismael

السؤال

أريد طريقة لتغيير ألوان المحاور في Matplotlib، على سبيل المثال في الكود التالي:

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-2, 2, 50)
y1 = x**3
y2 = x**2
fig, ax = plt.subplots()
ax.plot(x, y1, c = 'black',label = 'x^3')
ax.plot(x, y2, c = 'c',label = 'x^2')
leg = plt.legend(title="your_title")
plt.show()

1.png.3e0cdbec7bba6faae230b49641b85f13.png

 

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

Recommended Posts

  • 0

يمكنك القيام بتغييرها بالشكل التالي:

ax.spines['right'].set_color('color')
ax.spines['left'].set_color('color')
ax.spines['bottom'].set_color('color')
ax.spines['top'].set_color('color') 

وبالتالي يكون الكود:

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-2, 2, 50)
y1 = x**3
y2 = x**2
fig, ax = plt.subplots()
ax.plot(x, y1, c = 'black',label = 'x^3')
ax.plot(x, y2, c = 'c',label = 'x^2')
leg = plt.legend(title="your_title")
ax.spines['bottom'].set_color('blue')
ax.spines['top'].set_color('y') 
ax.spines['right'].set_color('red')
ax.spines['left'].set_color('red')
plt.show()

والنتيجة:
index.png.3054a7cf4c569e395273852880cc9c73.png
كذلك يمكنك تغيير ألوان العلامات ticks من خلال:

ax.tick_params(axis='x', colors='red')
ax.tick_params(axis='y', colors='red')

أو التسميات label:

ax.yaxis.label.set_color('red')
ax.xaxis.label.set_color('red')

أو العنوان title:

ax.title.set_color('red')

 

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

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

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

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

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

  • إعلانات

  • تابعنا على



×
×
  • أضف...