新浪博客

使用matplotlib给subplot添加标注

2015-12-27 00:26阅读:
import matplotlib.pyplot as plt
import numpy as np
x1 = np.linspace(0.0, 5.0)
x2 = np.linspace(0.0, 2.0)
y1 = np.cos(2 * np.pi * x1) * np.exp(-x1)
y2 = np.cos(2 * np.pi * x2)

def figure_label(text):
plt.annotate(text, xy=(-1.1, 1.1), xycoords='axes fraction', fontsize=12,
xytext=(0, 0), textcoords='offset points',
ha='right', va='top')

plt.subplot(2, 1, 1)
plt.plot(x1, y1, 'yo-')
plt.title('A tale of 2 subplots')
plt.ylabel('Damped oscillation')
figure_label('A')
plt.subplot(2, 1, 2)
plt.plot(x2, y2, 'r.-')
plt.
xlabel('time (s)')
plt.ylabel('Undamped')
figure_label('B')
plt.show()
使用matplotlib给subplot添加标注

我的更多文章

下载客户端阅读体验更佳

APP专享