|
8 | 8 | import matplotlib.pyplot as plt |
9 | 9 | import numpy as np |
10 | 10 |
|
11 | | -# Fixing random state for reproducibility |
12 | | -np.random.seed(19680801) |
13 | 11 |
|
14 | | -fig, ax = plt.subplots() |
| 12 | +def adjust_spines(ax, visible_spines): |
| 13 | + ax.label_outer(remove_inner_ticks=True) |
| 14 | + ax.grid(color='0.9') |
15 | 15 |
|
16 | | -image = np.random.uniform(size=(10, 10)) |
17 | | -ax.imshow(image, cmap=plt.cm.gray) |
18 | | -ax.set_title('dropped spines') |
| 16 | + for loc, spine in ax.spines.items(): |
| 17 | + if loc in visible_spines: |
| 18 | + spine.set_position(('outward', 10)) # outward by 10 points |
| 19 | + else: |
| 20 | + spine.set_visible(False) |
19 | 21 |
|
20 | | -# Move left and bottom spines outward by 10 points |
21 | | -ax.spines[['left', 'bottom']].set_position(('outward', 10)) |
22 | | -# Hide the right and top spines |
23 | | -ax.spines[['top', 'right']].set_visible(False) |
| 22 | + |
| 23 | +x = np.linspace(0, 2 * np.pi, 100) |
| 24 | + |
| 25 | +fig, axs = plt.subplots(2, 2) |
| 26 | + |
| 27 | +axs[0, 0].plot(x, np.sin(x)) |
| 28 | +axs[0, 1].plot(x, np.cos(x)) |
| 29 | +axs[1, 0].plot(x, -np.cos(x)) |
| 30 | +axs[1, 1].plot(x, -np.sin(x)) |
| 31 | + |
| 32 | +adjust_spines(axs[0, 0], ['left']) |
| 33 | +adjust_spines(axs[0, 1], []) |
| 34 | +adjust_spines(axs[1, 0], ['left', 'bottom']) |
| 35 | +adjust_spines(axs[1, 1], ['bottom']) |
24 | 36 |
|
25 | 37 | plt.show() |
0 commit comments