Matplotlib绘制外部情节

时间:2015-07-09 12:51:57

标签: python matplotlib plot

我想在情节下绘制矩形。我尝试使用matplotlib.patches矩形,但只有在我不在子图中绘制内容时才显示矩形:

import numpy as np
import matplotlib.pyplot as plt
import seaborn
from matplotlib.patches import Rectangle

t1 = np.arange(0.0, 5.0, 0.9)
t2 = np.arange(0.0, 50.0, 0.02)

plt.figure(1, figsize=(14, 6))
plt.subplot(211)

# If I uncommend this line, the rectangles will disappear
# plt.plot(t1, t1, 'bo', t2, t2, 'k')

# Draw some rectangles under the plot
someX, someY = 0.1, -0.3
currentAxis = plt.gca()
tri = Rectangle((someX - .1, someY - .1), 0.005, 0.2, fill='b', alpha=1)
currentAxis.add_patch(tri)
tri.set_clip_on(False)

someX, someY = 0.5, -0.3
currentAxis = plt.gca()
tri = Rectangle((someX - .1, someY - .1), 0.005, 0.2, fill='b', alpha=1)
currentAxis.add_patch(tri)
tri.set_clip_on(False)

plt.show()

我想要的只是在某个位置绘制一些线条(如在地毯上)。

由于

0 个答案:

没有答案