Python for Finance: Analyze Big Financial Data

(Elle) #1
Figure 5-5. Plot with custom axis limits

For the sake of better readability, a plot usually contains a number of labels — e.g., a title


and labels describing the nature of x and y values. These are added by the functions


plt.title, plt.xlabel, and plt.ylabel, respectively. By default, plot plots continuous


lines, even if discrete data points are provided. The plotting of discrete points is


accomplished by choosing a different style option. Figure 5-6 overlays (red) points and a


(blue) line with line width of 1.5 points:


In  [ 8 ]:  plt.figure(figsize=( 7 ,     4 ))
# the figsize parameter defines the
# size of the figure in (width, height)
plt.plot(y.cumsum(), ‘b’, lw=1.5)
plt.plot(y.cumsum(), ‘ro’)
plt.grid(True)
plt.axis(‘tight’)
plt.xlabel(‘index’)
plt.ylabel(‘value’)
plt.title(‘A Simple Plot’)

Figure 5-6. Plot with typical labels

By default, plt.plot supports the color abbreviations in Table 5-2.


Table 5-2. Standard color abbreviations


Character Color

b

Blue
Free download pdf