@@ -236,6 +236,7 @@ As usual, we'll start by importing some Python modules.
236
236
import numpy as np
237
237
from collections import namedtuple
238
238
import matplotlib.pyplot as plt
239
+ plt.rcParams['figure.dpi'] = 200
239
240
```
240
241
241
242
First, we store parameters in a `namedtuple`:
@@ -338,7 +339,7 @@ Now we use the following function to plot the result
338
339
339
340
```{code-cell} ipython3
340
341
def plot_sequences(sequences, labels):
341
- fig, axs = plt.subplots(len(sequences), 1, figsize=[5, 12], dpi=200 )
342
+ fig, axs = plt.subplots(len(sequences), 1, figsize=[5, 12])
342
343
for ax, seq, label in zip(axs, sequences, labels):
343
344
ax.plot(range(len(seq)), seq, label=label)
344
345
ax.set_ylabel(label)
@@ -524,10 +525,11 @@ p_seq_2_regime2 = np.concatenate([p_seq_2_path1[:T1+1],
524
525
525
526
```{code-cell} ipython3
526
527
:tags: [hide-input]
528
+
527
529
T_seq = range(T+2)
528
530
529
531
# plot both regimes
530
- fig, ax = plt.subplots(5, 1, figsize=[5, 12], dpi=200 )
532
+ fig, ax = plt.subplots(5, 1, figsize=[5, 12])
531
533
532
534
# Configuration for each subplot
533
535
plot_configs = [
@@ -543,20 +545,22 @@ plot_configs = [
543
545
'ylabel': r'$p$'}
544
546
]
545
547
546
- # Loop through each subplot configuration
547
- for axi, config in zip(ax, plot_configs):
548
- for data in config['data']:
549
- if len(data) == 3: # Plot with label for legend
550
- axi.plot(data[0], data[1], label=data[2])
551
- else: # Plot without label
552
- axi.plot(data[0], data[1])
553
- axi.set_ylabel(config['ylabel'])
554
- axi.set_xlabel(r'$t$')
555
- if 'label' in config: # If there's a label, add a legend
556
- axi.legend()
557
-
558
- plt.tight_layout()
559
- plt.show()
548
+ def generate_plots(plot_configs, ax):
549
+
550
+ # Loop through each subplot configuration
551
+ for axi, config in zip(ax, plot_configs):
552
+ for data in config['data']:
553
+ if len(data) == 3: # Plot with label for legend
554
+ axi.plot(data[0], data[1], label=data[2])
555
+ axi.legend()
556
+ else: # Plot without label
557
+ axi.plot(data[0], data[1])
558
+ axi.set_ylabel(config['ylabel'])
559
+ axi.set_xlabel(r'$t$')
560
+ plt.tight_layout()
561
+ plt.show()
562
+
563
+ generate_plots(plot_configs, ax)
560
564
```
561
565
562
566
We invite you to compare these graphs with corresponding ones for the foreseen stabilization analyzed in experiment 1 above.
@@ -582,36 +586,25 @@ unanticipated, as in experiment 2.
582
586
583
587
```{code-cell} ipython3
584
588
:tags: [hide-input]
585
- # compare foreseen vs unforeseen shock
586
- fig, ax = plt.subplots(5, figsize=[5, 12], dpi=200)
587
-
588
- plot_data = [
589
- (T_seq[:-1], [μ_seq_2], r'$\mu$', ['']),
590
- (T_seq, [π_seq_2, π_seq_1], r'$\pi$', ['Unforeseen', 'Foreseen']),
591
- (T_seq, [m_seq_2_regime1 - p_seq_2_regime1, m_seq_1 - p_seq_1],
592
- r'$m - p$', ['Unforeseen', 'Foreseen']),
593
- (T_seq, [m_seq_2_regime1, m_seq_2_regime2, m_seq_1], r'$m$',
594
- ['Unforeseen (Smooth $m_{T_1}$)',
595
- 'Unforeseen ($m_{T_1}$ jumps)',
596
- 'Foreseen shock']),
597
- (T_seq, [p_seq_2_regime1, p_seq_2_regime2, p_seq_1], r'$p$',
598
- ['Unforseen (Smooth $m_{T_1}$)',
599
- 'Unforseen ($m_{T_1}$ jumps)',
600
- 'Foreseen shock'])
601
- ]
602
589
603
- for i, (times, sequences, ylabel, labels) in enumerate(plot_data):
604
- for seq, label in zip(sequences, labels):
605
- ax[i].plot(times, seq, label=label)
606
- ax[i].set_ylabel(ylabel)
607
- if labels[0]:
608
- ax[i].legend()
590
+ # compare foreseen vs unforeseen shock
591
+ fig, ax = plt.subplots(5, figsize=[5, 12])
609
592
610
- for axis in ax:
611
- axis.set_xlabel(r'$t$')
593
+ plot_configs = [
594
+ {'data': [(T_seq[:-1], μ_seq_2)], 'ylabel': r'$\mu$'},
595
+ {'data': [(T_seq, π_seq_2, 'Unforeseen'),
596
+ (T_seq, π_seq_1, 'Foreseen')], 'ylabel': r'$p$'},
597
+ {'data': [(T_seq, m_seq_2_regime1 - p_seq_2_regime1, 'Unforeseen'),
598
+ (T_seq, m_seq_1 - p_seq_1, 'Foreseen')], 'ylabel': r'$m - p$'},
599
+ {'data': [(T_seq, m_seq_2_regime1, 'Unforeseen (Smooth $m_{T_1}$)'),
600
+ (T_seq, m_seq_2_regime2, 'Unforeseen ($m_{T_1}$ jumps)'),
601
+ (T_seq, m_seq_1, 'Foreseen')], 'ylabel': r'$m$'},
602
+ {'data': [(T_seq, p_seq_2_regime1, 'Unforeseen (Smooth $m_{T_1}$)'),
603
+ (T_seq, p_seq_2_regime2, 'Unforeseen ($m_{T_1}$ jumps)'),
604
+ (T_seq, p_seq_1, 'Foreseen')], 'ylabel': r'$p$'}
605
+ ]
612
606
613
- plt.tight_layout()
614
- plt.show()
607
+ generate_plots(plot_configs, ax)
615
608
```
616
609
617
610
It is instructive to compare the preceding graphs with graphs of log price levels and inflation rates for data from four big inflations described in
0 commit comments