Dùng ax.text() với tham số rotation để xoay văn bản tùy ý trên từng subplot.
- Tạo figure, ax = add_subplot().
- subplots_adjust(top=0.85), suptitle.
- set_title, set_xlabel, set_ylabel.
- ax.axis([0,10,0,10]).
- ax.text() với fontsize, fontweight, rotation, bbox, transform=ax.transAxes.
- ax.plot([2],[1],'o'), ax.annotate với mũi tên.
- show().
Ví dụ
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()
Kết quả
Biểu đồ minh họa các loại text, annotation, rotation, box, unicode, transform coordinates.