Figure 5-8. Plot with labeled data sets
Multiple data sets with a similar scaling, like simulated paths for the same financial risk
factor, can be plotted using a single y-axis. However, often data sets show rather different
scalings and the plotting of such data with a single y scale generally leads to a significant
loss of visual information. To illustrate the effect, we scale the first of the two data subsets
by a factor of 100 and plot the data again (cf. Figure 5-9):
In [ 12 ]: y[:, 0 ] = y[:, 0 ] * 100
plt.figure(figsize=( 7 , 4 ))
plt.plot(y[:, 0 ], lw=1.5, label=‘1st’)
plt.plot(y[:, 1 ], lw=1.5, label=‘2nd’)
plt.plot(y, ‘ro’)
plt.grid(True)
plt.legend(loc= 0 )
plt.axis(‘tight’)
plt.xlabel(‘index’)
plt.ylabel(‘value’)
plt.title(‘A Simple Plot’)
Figure 5-9. Plot with two differently scaled data sets
Inspection of Figure 5-9 reveals that the first data set is still “visually readable,” while the
second data set now looks like a straight line with the new scaling of the y-axis. In a sense,
information about the second data set now gets “visually lost.” There are two basic
approaches to resolve this problem:
Use of two y-axes (left/right)