Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีเพิ่มขอบสีดำให้กับ matplotlib 2.0 'ax' object ใน Python 3

ในการเพิ่มขอบสีดำให้กับ matplotlib 2.0 'ax' object ใน Python เราสามารถทำตามขั้นตอนต่อไปนี้:

  • ตั้งค่าขนาดรูปและปรับ padding ระหว่างและรอบ subplots
  • ตั้งค่า axes edgecolor เป็นสีดำ
  • ตั้งค่า axes linewidth เป็น 2.50
  • เริ่มต้นตัวแปร N เพื่อรับจำนวนข้อมูลตัวอย่าง
  • สร้างจุดข้อมูล x และ y ด้วย numpy
  • พลอต x และ y ด้วยเมธอด plot()
  • เพื่อแสดงรูป ใช้เมธอด show()

ตัวอย่าง

import matplotlib.pyplot as plt
import numpy as np

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

plt.rcParams["axes.edgecolor"] = "black"
plt.rcParams["axes.linewidth"] = 2.50

N = 10
x = np.random.randint(low=0, high=N, size=N)
y = np.random.randint(low=0, high=N, size=N)

plt.plot(x, y, color='red')
plt.show()

ผลลัพธ์

วิธีเพิ่มขอบสีดำให้กับ matplotlib 2.0  ax  object ใน Python 3วิธีเพิ่มขอบสีดำให้กับ matplotlib 2.0  ax  object ใน Python 3