I have script which draw candlestick chart. I added two annotations to this script. One is "Last data" which show last candle and the second annotations should show point in the future. But for some reason it is not visible on the picture. How can I make it visible? I was trying to change chart width and plt.axis values but didn't find solution.
#!/usr/bin/env python
import matplotlib.pyplot as plt
from matplotlib.dates import DateFormatter, WeekdayLocator, HourLocator, \
DayLocator, MONDAY
from matplotlib.finance import quotes_historical_yahoo, candlestick,\
plot_day_summary, candlestick2
from matplotlib.patches import Ellipse, Circle
el = Ellipse((2, -1), 0.5, 0.5)
# (Year, month, day) tuples suffice as args for quotes_historical_yahoo
date1 = ( 2013, 11, 10)
date2 = ( 2013, 12, 29)
mondays = WeekdayLocator(MONDAY) # major ticks on the mondays
alldays = DayLocator() # minor ticks on the days
weekFormatter = DateFormatter('%b %d') # e.g., Jan 12
dayFormatter = DateFormatter('%d') # e.g., 12
quotes = quotes_historical_yahoo('INTC', date1, date2)
if len(quotes) == 0:
raise SystemExit
fig, ax = plt.subplots()
fig.subplots_adjust(bottom=0.2)
candlestick(ax, quotes, width=0.6)
ax.xaxis_date()
plt.setp( plt.gca().get_xticklabels(), rotation=45, horizontalalignment='right')
dt = quotes[0][0]
ax.annotate(
'Last data',
xy=(dt+16, 24),
xytext=(dt+3, 25),
arrowprops=dict(arrowstyle='simple', fc="0.6", ec="none", patchB=el, connectionstyle="arc3,rad=0.3", facecolor='black')
)
ax.annotate(
'Future',
xy=(dt+19, 24.5),
xytext=(dt+2, 23.7),
arrowprops=dict(arrowstyle='simple', fc="0.6", ec="none", patchB=el, connectionstyle="arc3,rad=0.3", facecolor='black')
)
plt.savefig('test.png')
You just need to change the xlimit on your graph:
ax = plt.gca()
ax.set_xlim([start_data, end_date])
plt.draw()