Python for Finance: Analyze Big Financial Data

(Elle) #1
Figure 5-20. Candlestick chart for financial data

In the preceding code, plt.setp(plt.gca().get_xticklabels(), rotation=30) grabs


the x-axis labels and rotates them by 30 degrees. To this end, the function plt.gca is used,


which returns the current figure object. The method call of get_xticklabels then


provides the tick labels for the x-axis of the figure.


Table 5-6 provides a description of the different parameters the mpf.candlestick function


takes.


Table 5-6. Parameters for mpf.candlestick


Parameter Description

ax

An Axes instance to plot to

quotes

Financial data to plot (sequence of time, open, close, high, low sequences)

width

Fraction of a day for the rectangle width

colorup

The color of the rectangle where close >= open

colordown

The color of the rectangle where close < open

alpha

The rectangle alpha level

A rather similar plot type is provided by the plot_day_summary function, which is used in


the same fashion as the candlestick function and with similar parameters. Here, opening


and closing values are not illustrated by a colored rectangle but rather by two small


horizontal lines, as Figure 5-21 shows:


In  [ 29 ]: fig,    ax  =   plt.subplots(figsize=( 8 ,   5 ))
mpf.plot_day_summary(ax, quotes, colorup=‘b’, colordown=‘r’)
Free download pdf