%matplotlib inline from __future__ import print_function, division import numpy as np import matplotlib.pyplot as plt fig, ax = plt.subplots() ax.text(0.5, 0.5, 'hello world: $\int_0^\infty e^x dx$', size=24, ha='center', va='center'); fig.text(0, 0, 'bottom-left corner') fig.text(1, 1, 'top-right corner', ha='left', va='top') fig fig, ax = plt.subplots() ax.annotate('0.25 on axes', (0.25, 0.25), textcoords='axes fraction', size=20) ax.annotate('0.25 on data', (0.25, 0.25), textcoords='data', size=20) ax.set_ylim(0, 0.5); fig, ax = plt.subplots() ax.annotate('origin is here', (0, 0), (0.75, 0.75), arrowprops=dict(arrowstyle='->', connectionstyle='arc3, rad=0.5'), xycoords='data', textcoords='axes fraction'); fig, ax = plt.subplots() x = np.linspace(0, 10) ax.plot(x, np.sin(x)) ax.xaxis.set_major_locator(plt.MultipleLocator(0.8)) ax.yaxis.set_major_locator(plt.MaxNLocator(3)) ax.xaxis.set_minor_locator(plt.MultipleLocator(0.4)) ax.yaxis.set_minor_locator(plt.NullLocator()) # no ticks (default) ax.xaxis.set_major_formatter(plt.FormatStrFormatter('%.2f')) # float with two decimals def tickformat(val, pos): if val > 0: return "positive" elif val < 0: return "negative" else: return "zero" ax.yaxis.set_major_formatter(plt.FuncFormatter(tickformat)) ax.set_ylim(-1.2, 1.2);