Figure 5-15. Scatter plot with third dimension
Another type of plot, the histogram, is also often used in the context of financial returns.
Figure 5-16 puts the frequency values of the two data sets next to each other in the same
plot:
In [ 21 ]: plt.figure(figsize=( 7 , 4 ))
plt.hist(y, label=[‘1st’, ‘2nd’], bins= 25 )
plt.grid(True)
plt.legend(loc= 0 )
plt.xlabel(‘value’)
plt.ylabel(‘frequency’)
plt.title(‘Histogram’)
Figure 5-16. Histogram for two data sets
Since the histogram is such an important plot type for financial applications, let us take a
closer look at the use of plt.hist. The following example illustrates the parameters that
are supported:
plt.hist(x, bins=10, range=None, normed=False, weights=None, cumulative=False,
bottom=None, histtype=‘bar’, align=‘mid’, orientation=‘vertical’, rwidth=None,
log=False, color=None, label=None, stacked=False, hold=None, **kwargs)
Table 5-5 provides a description of the main parameters of the plt.hist function.
Table 5-5. Parameters for plt.hist