เพื่อย้ายป้ายแกนจากด้านล่างไปด้านบนโดยไม่เพิ่ม ticks
- ตั้งค่าขนาดรูปและ padding ระหว่าง subplots
- สร้างข้อมูลสุ่มเมทริกซ์ 5x5
- แสดงข้อมูลเป็นภาพด้วย imshow()
- ใช้ 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
data = np.random.rand(5, 5)
plt.imshow(data, cmap="copper")
plt.tick_params(axis='both', which='major',
labelsize=10, labelbottom=False,
bottom=True, top=False, labeltop=True)
plt.show()ผลลัพธ์
