【发布时间】:2015-09-18 16:43:06
【问题描述】:
我尝试使用以下代码在带有日期时间 x 轴的图表上绘制一个矩形:
from datetime import datetime, timedelta
from matplotlib.patches import Rectangle
import matplotlib.pyplot as plt
# Create new plot
fig = plt.figure()
ax = fig.add_subplot(111)
# Create rectangle
startTime = datetime.now()
width = timedelta(seconds = 1)
endTime = startTime + width
rect = Rectangle((startTime, 0), width, 1, color='yellow')
# Plot rectangle
ax.add_patch(rect) ### ERROR HERE!!! ###
plt.xlim([startTime, endTime])
plt.ylim([0, 1])
plt.show()
但是,我得到了错误:
TypeError: unsupported operand type(s) for +: 'float' and 'datetime.timedelta'
怎么了? (我使用的是 matplotlib 1.0.1 版)
【问题讨论】:
标签: python python-2.7 matplotlib