ในการเปลี่ยนสีใบหน้าของพล็อตโดยใช้ matplotlib เราสามารถทำตามขั้นตอนต่อไปนี้ -
- กำหนดขนาดรูปและปรับช่องว่างภายในระหว่างและรอบๆ แผนผังย่อย
- สร้างจุดข้อมูล x และ y โดยใช้ numpy
- สร้างร่างและชุดแผนย่อย
- พล็อตจุดข้อมูล x และ y โดยใช้ plot() เมธอดที่มี color=yellow และ linewidth=7
- กำหนดสีหน้าของแกนโดยใช้ set_facecolor() .
- หากต้องการแสดงรูป ให้ใช้ show() วิธีการ
ตัวอย่าง
from matplotlib import pyplot as plt
import numpy as np
# Set the figure size
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
# Create x and y data points
x = np.linspace(-10, 10, 100)
y = np.sin(x)
# Create a figure and set of subplots
fig, ax = plt.subplots()
# Plot the x and y data points with color
ax.plot(x, y, color='yellow', lw=7)
# Set the facecolor
ax.set_facecolor('red')
plt.show() ผลลัพธ์
มันจะสร้างผลลัพธ์ต่อไปนี้
