1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| import matplotlib.pyplot as plt import numpy as np
def addtext(ax, props): ax.text(0.5, 0.5, 'text 0', props, rotation=0) ax.text(1.5, 0.5, 'text 45', props, rotation=45) ax.text(2.5, 0.5, 'text 135', props, rotation=135) ax.text(3.5, 0.5, 'text 225', props, rotation=225) ax.text(4.5, 0.5, 'text -45', props, rotation=-45) for x in range(0, 5): ax.scatter(x + 0.5, 0.5, color='r', alpha=0.5) ax.set_yticks([0, .5, 1]) ax.set_xlim(0, 5) ax.grid(True)
bbox = {'fc': '0.8', 'pad': 0}
fig, axs = plt.subplots(2, 1)
addtext(axs[0], {'ha': 'center', 'va': 'center', 'bbox': bbox}) axs[0].set_xticks(np.arange(0, 5.1, 0.5), []) axs[0].set_ylabel('center / center')
addtext(axs[1], {'ha': 'left', 'va': 'bottom', 'bbox': bbox}) axs[1].set_xticks(np.arange(0, 5.1, 0.5)) axs[1].set_ylabel('left / bottom')
plt.show()
|