|
| 1 | + |
| 2 | +#################### |
| 3 | +Adding text to plots |
| 4 | +#################### |
| 5 | + |
| 6 | +.. plot:: |
| 7 | + |
| 8 | + import matplotlib |
| 9 | + import matplotlib.pyplot as plt |
| 10 | + |
| 11 | + fig = plt.figure() |
| 12 | + ax = fig.add_subplot() |
| 13 | + fig.subplots_adjust(top=0.85) |
| 14 | + |
| 15 | + # Set titles for the figure and the subplot respectively |
| 16 | + fig.suptitle('bold figure suptitle', fontsize=14, fontweight='bold') |
| 17 | + ax.set_title('axes title') |
| 18 | + |
| 19 | + ax.set_xlabel('xlabel') |
| 20 | + ax.set_ylabel('ylabel') |
| 21 | + |
| 22 | + # Set both x- and y-axis limits to [0, 10] instead of default [0, 1] |
| 23 | + ax.axis([0, 10, 0, 10]) |
| 24 | + |
| 25 | + ax.text(3, 8, 'boxed italics text in data coords', style='italic', |
| 26 | + bbox={'facecolor': 'red', 'alpha': 0.5, 'pad': 10}) |
| 27 | + |
| 28 | + ax.text(2, 6, r'an equation: $E=mc^2$', fontsize=15) |
| 29 | + |
| 30 | + ax.text(3, 2, 'Unicode: Institut für Festkörperphysik') |
| 31 | + |
| 32 | + ax.text(0.95, 0.01, 'colored text in axes coords', |
| 33 | + verticalalignment='bottom', horizontalalignment='right', |
| 34 | + transform=ax.transAxes, |
| 35 | + color='green', fontsize=15) |
| 36 | + |
| 37 | + ax.plot([2], [1], 'o') |
| 38 | + ax.annotate('annotate', xy=(2, 1), xytext=(3, 4), |
| 39 | + arrowprops=dict(facecolor='black', shrink=0.05)) |
| 40 | + |
| 41 | + plt.show() |
| 42 | + |
| 43 | +.. toctree:: |
| 44 | + :maxdepth: 1 |
| 45 | + |
| 46 | + ../../../tutorials/text/text_intro.rst |
| 47 | + ../../../tutorials/intermediate/legend_guide.rst |
| 48 | + ../../../tutorials/text/annotations.rst |
| 49 | + ../../../tutorials/text/text_props.rst |
| 50 | + ../../../tutorials/text/mathtext.rst |
| 51 | + ../../../tutorials/text/usetex.rst |
| 52 | + ../fonts.rst |
0 commit comments