หมุนข้อความแกนในแต่ละ subplot
ใช้ text พร้อมพารามิเตอร์ rotation เพื่อหมุนข้อความในแต่ละ subplot
ขั้นตอน
- สร้าง figure ใหม่
- เพิ่ม axes ด้วย add_subplot()
- ปรับ layout ด้วย subplots_adjust()
- เพิ่ม suptitle ด้วย suptitle()
- ตั้งค่า title, xlabel, ylabel
- สร้างแกนพร้อมพิกัด
- เพิ่มข้อความพร้อม fontsize, fontweight, rotation
- วาดจุดเดียวและ annotate พร้อมลูกศร
- แสดงด้วย show()
ตัวอย่างโค้ด
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
fig = plt.figure()
ax = fig.add_subplot()
fig.subplots_adjust(top=0.85)
fig.suptitle('bold figure suptitle', fontsize=14, fontweight='bold')
ax.set_title('axes title')
ax.set_xlabel('xlabel')
ax.set_ylabel('ylabel')
ax.axis([0, 10, 0, 10])
ax.text(3, 8, 'boxed italics text in data coords', style='italic',
bbox={'facecolor': 'red', 'alpha': 0.5, 'pad': 10})
ax.text(2, 6, r'an equation: $E=mc^2$', fontsize=15)
ax.text(3, 2, 'unicode: Institut f\u00fcr Festk\u00f6rperphysik')
ax.text(0.95, 0.01, 'colored text in axes coords',
verticalalignment='bottom', horizontalalignment='right',
transform=ax.transAxes, color='green', fontsize=15)
ax.plot([2], [1], 'o')
ax.annotate('annotate', xy=(2, 1), xytext=(3, 4),
arrowprops=dict(facecolor='black', shrink=0.05))
plt.show()
ผลลัพธ์
