Python for Finance: Analyze Big Financial Data

(Elle) #1
Figure 5-4. Plot with grid and tight axes

Other options for plt.axis are given in Table 5-1, the majority of which have to be


passed as a string object.


Table 5-1. Options for plt.axis


Parameter Description

Empty

Returns current axis limits

off

Turns axis lines and labels off

equal

Leads to equal scaling

scaled

Equal scaling via dimension changes

tight

Makes all data visible (tightens limits)

image

Makes all data visible (with data limits)

[xmin, xmax, ymin, ymax]

Sets limits to given ( list of) values

In addition, you can directly set the minimum and maximum values of each axis by using


plt.xlim and plt.ylim. The following code provides an example whose output is shown


in Figure 5-5:


In  [ 7 ]:  plt.plot(y.cumsum())
plt.grid(True)
plt.xlim(- 1 , 20 )
plt.ylim(np.min(y.cumsum()) - 1 ,
np.max(y.cumsum()) + 1 )
Free download pdf