1""" 2========================================= 3Tick formatting using the ScalarFromatter 4========================================= 5 6The example shows use of ScalarFormatter with different settings. 7 8Example 1 : Default 9 10Example 2 : With no Numerical Offset 11 12Example 3 : With Mathtext 13""" 14import matplotlib.pyplot as plt 15import numpy as np 16from matplotlib.ticker import ScalarFormatter 17 18############################################################################### 19# Example 1 20 21x = np.arange(0, 1, .01) 22fig, [[ax1, ax2], [ax3, ax4]] = plt.subplots(2, 2, figsize=(6, 6)) 23fig.text(0.5, 0.975, 'The new formatter, default settings', 24 horizontalalignment='center', 25 verticalalignment='top') 26 27ax1.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5) 28ax1.xaxis.set_major_formatter(ScalarFormatter()) 29ax1.yaxis.set_major_formatter(ScalarFormatter()) 30 31ax2.plot(x * 1e5, x * 1e-4) 32ax2.xaxis.set_major_formatter(ScalarFormatter()) 33ax2.yaxis.set_major_formatter(ScalarFormatter()) 34 35ax3.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10) 36ax3.xaxis.set_major_formatter(ScalarFormatter()) 37ax3.yaxis.set_major_formatter(ScalarFormatter()) 38 39ax4.plot(-x * 1e5, -x * 1e-4) 40ax4.xaxis.set_major_formatter(ScalarFormatter()) 41ax4.yaxis.set_major_formatter(ScalarFormatter()) 42 43fig.subplots_adjust(wspace=0.7, hspace=0.6) 44 45############################################################################### 46# Example 2 47 48x = np.arange(0, 1, .01) 49fig, [[ax1, ax2], [ax3, ax4]] = plt.subplots(2, 2, figsize=(6, 6)) 50fig.text(0.5, 0.975, 'The new formatter, no numerical offset', 51 horizontalalignment='center', 52 verticalalignment='top') 53 54ax1.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5) 55ax1.xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) 56ax1.yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) 57 58ax2.plot(x * 1e5, x * 1e-4) 59ax2.xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) 60ax2.yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) 61 62ax3.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10) 63ax3.xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) 64ax3.yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) 65 66ax4.plot(-x * 1e5, -x * 1e-4) 67ax4.xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) 68ax4.yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) 69 70fig.subplots_adjust(wspace=0.7, hspace=0.6) 71 72############################################################################### 73# Example 3 74 75x = np.arange(0, 1, .01) 76fig, [[ax1, ax2], [ax3, ax4]] = plt.subplots(2, 2, figsize=(6, 6)) 77fig.text(0.5, 0.975, 'The new formatter, with mathtext', 78 horizontalalignment='center', 79 verticalalignment='top') 80 81ax1.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5) 82ax1.xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) 83ax1.yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) 84 85ax2.plot(x * 1e5, x * 1e-4) 86ax2.xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) 87ax2.yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) 88 89ax3.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10) 90ax3.xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) 91ax3.yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) 92 93ax4.plot(-x * 1e5, -x * 1e-4) 94ax4.xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) 95ax4.yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) 96 97fig.subplots_adjust(wspace=0.7, hspace=0.6) 98 99plt.show() 100