Matplotlib مضيفا خطوط الشبكة
أضف خطوط الشبكة إلى قطعة الأرض
باستخدام Pyplot ، يمكنك استخدام grid()
الوظيفة لإضافة خطوط الشبكة إلى المؤامرة.
مثال
أضف خطوط الشبكة إلى المؤامرة:
import numpy as np
import matplotlib.pyplot as plt
x = np.array([80,
85, 90, 95, 100, 105, 110, 115, 120, 125])
y = np.array([240, 250, 260,
270, 280, 290, 300, 310, 320, 330])
plt.title("Sports Watch Data")
plt.xlabel("Average Pulse")
plt.ylabel("Calorie Burnage")
plt.plot(x,
y)
plt.grid()
plt.show()
نتيجة:
حدد خطوط الشبكة المطلوب عرضها
يمكنك استخدام axis
المعلمة في grid()
الوظيفة لتحديد خطوط الشبكة المراد عرضها.
القيم القانونية هي: "x" و "y" و "كلاهما". القيمة الافتراضية هي "كلاهما".
مثال
عرض خطوط الشبكة للمحور السيني فقط:
import numpy as np
import matplotlib.pyplot as plt
x = np.array([80,
85, 90, 95, 100, 105, 110, 115, 120, 125])
y = np.array([240, 250, 260,
270, 280, 290, 300, 310, 320, 330])
plt.title("Sports Watch Data")
plt.xlabel("Average Pulse")
plt.ylabel("Calorie Burnage")
plt.plot(x,
y)
plt.grid(axis = 'x')
plt.show()
نتيجة:
مثال
عرض خطوط الشبكة للمحور y فقط:
import numpy as np
import matplotlib.pyplot as plt
x = np.array([80,
85, 90, 95, 100, 105, 110, 115, 120, 125])
y = np.array([240, 250, 260,
270, 280, 290, 300, 310, 320, 330])
plt.title("Sports Watch Data")
plt.xlabel("Average Pulse")
plt.ylabel("Calorie Burnage")
plt.plot(x,
y)
plt.grid(axis = 'y')
plt.show()
نتيجة:
تعيين خصائص الخط للشبكة
يمكنك أيضًا تعيين خصائص خط الشبكة ، مثل هذا: الشبكة (اللون = ' اللون ' ، النمط الخطي = ' النمط الخطي ' ، عرض الخط = رقم ).
مثال
عيّن خصائص خط الشبكة:
import numpy as np
import matplotlib.pyplot as plt
x = np.array([80,
85, 90, 95, 100, 105, 110, 115, 120, 125])
y = np.array([240, 250, 260,
270, 280, 290, 300, 310, 320, 330])
plt.title("Sports Watch Data")
plt.xlabel("Average
Pulse")
plt.ylabel("Calorie Burnage")
plt.plot(x,
y)
plt.grid(color = 'green', linestyle = '--', linewidth = 0.5)
plt.show()