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

วิธีเปลี่ยนขนาดฟอนต์ของตัวเลขบนแกน (Scale) ใน Matplotlib


เพื่อเปลี่ยนขนาดฟอนต์ของตัวเลขบนแกนใน Matplotlib ใช้ labelsize ในเมธอด tick_params()

ขั้นตอน

  • ตั้งค่าขนาดรูปและ padding ระหว่าง subplots
  • สร้าง figure และ subplots
  • พลอต x ด้วย plot()
  • เปลี่ยนขนาดฟอนต์ scale ด้วย labelsize ใน tick_params()
  • แสดงรูปด้วย show()

ตัวอย่าง

import numpy as np
from matplotlib import pyplot as plt

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

fig, ax = plt.subplots()
x = np.random.rand(10)
ax.plot(x)
ax.tick_params(axis='x', labelsize=20)
plt.show()

ผลลัพธ์

วิธีเปลี่ยนขนาดฟอนต์ของตัวเลขบนแกน (Scale) ใน Matplotlib