annotate diagonal python

Solutions on MaxInterview for annotate diagonal python by the best coders in the world

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