【发布时间】:2016-06-16 13:43:16
【问题描述】:
我尝试画一条对角线,但它不起作用。
我可以使用 axhline 和 axvline 绘制水平和垂直线
但我不知道对角线我使用 plot 但它不起作用
这是我的一些代码和结果:
while (loop < candleLength) :
date = stockData['date'][loop]
date = dateToFloat(date)
append = date, stockData['open'][loop], stockData['high'][loop], stockData['low'][loop], stockData['close'][loop]
ohlc.append(append)
loop += 1
fig = plt.figure()
ax = plt.subplot2grid((1,1), (0,0))
candlestick_ohlc(ax, ohlc, width=0.66, colorup='#4dff4d', colordown='#ff471a') # plt.plot([736062.0, 736118.0], [70, 70], 'k-', lable = 'example line')
for label in ax.xaxis.get_ticklabels():
label.set_rotation(45)
ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
ax.xaxis.set_major_locator(mondays)
ax.grid(True)
ax.text(buyPointTypeFloat, buyPrice, 'BUY', fontdict=font_dict)
ax.text(sellPointTypeFloat, sellPrice, 'SELL', fontdict=font_dict)
# ax.plot(x=buyPrice, y=sellPrice)
ax.axhline(y=sellPrice,color='k',ls='dashed')
ax.axhline(y=buyPrice,color='k',ls='dashed')
plt.xlabel('Date')
plt.ylabel('Price')
plt.title(stockName)
plt.subplots_adjust(left=0.09, bottom=0.20, right=0.94, top=0.90, wspace=0.2, hspace=0)
plt.show()
从图片中你会看到我在买入/卖出价上有 2 条水平线
但我想改用对角线。
谢谢。
【问题讨论】:
-
例如有什么问题?
plot([0,0],[1,1], ...), where you could get the extend from e.g. theaxis` 限制?
标签: python matplotlib candlestick-chart