|
90 | 90 | fig, ax = plt.subplots(1, figsize=(4, 10)) |
91 | 91 |
|
92 | 92 | for ix, level in enumerate(ts.levels[::-1]): |
93 | | - ldf = ts.data.loc[ts.data.Level == level, :] |
94 | | - for pix, period in ldf.iterrows(): |
95 | | - left, right = xlims[level] |
96 | | - if ix != len(ts.levels) - 1: |
| 93 | + if level in xlims: |
| 94 | + ldf = ts.data.loc[ts.data.Level == level, :] |
| 95 | + for pix, period in ldf.iterrows(): |
| 96 | + left, right = xlims[level] |
97 | 97 | time = np.mean(ts.text2age(period.Name)) |
98 | | - general = None |
99 | | - _ix = ix |
100 | | - while general is None: |
101 | | - try: |
102 | | - general = ts.named_age(time, level=ts.levels[::-1][_ix + 1]) |
103 | | - except: |
104 | | - pass |
105 | | - _ix += 1 |
106 | | - _l, _r = xlims[ts.levels[::-1][_ix]] |
107 | | - if _r > left: |
108 | | - left = _r |
| 98 | + if ix != len(ts.levels) - 1: |
| 99 | + general_bound = None |
| 100 | + _ix = ix |
| 101 | + while general_bound is None: |
| 102 | + try: |
| 103 | + _ix += 1 |
| 104 | + bound_level = ts.levels[::-1][_ix] |
| 105 | + general_bound = ts.named_age(time, level=bound_level) |
| 106 | + except IndexError: |
| 107 | + break |
| 108 | + if bound_level in xlims: |
| 109 | + _l, _r = xlims[bound_level] |
| 110 | + if _r > left: |
| 111 | + left = _r |
109 | 112 |
|
110 | | - rect = Rectangle( |
111 | | - (left, period.End), |
112 | | - right - left, |
113 | | - period.Start - period.End, |
114 | | - facecolor=period.Color, |
115 | | - edgecolor="k", |
116 | | - ) |
117 | | - ax.add_artist(rect) |
| 113 | + rect = Rectangle( |
| 114 | + (left, period.End), |
| 115 | + right - left, |
| 116 | + period.Start - period.End, |
| 117 | + facecolor=period.Color, |
| 118 | + edgecolor="k", |
| 119 | + ) |
| 120 | + ax.add_artist(rect) |
118 | 121 |
|
119 | | -ax.set_xticks([np.mean(xlims[lvl]) for lvl in ts.levels]) |
120 | | -ax.set_xticklabels(ts.levels, rotation=60) |
| 122 | +ax.set_xticks([np.mean(xlims[lvl]) for lvl in xlims.keys()]) |
| 123 | +ax.set_xticklabels(xlims.keys(), rotation=60) |
121 | 124 | ax.xaxis.set_ticks_position("top") |
122 | 125 | ax.set_xlim(0, 7) |
123 | 126 | ax.set_ylabel("Age (Ma)") |
|
0 commit comments