|
| 1 | +#!/usr/bin/env python |
| 2 | +# Demonstrating the improvements and options of the proposed new ScalarFormatter |
| 3 | +from pylab import * |
| 4 | +from matplotlib.ticker import NewScalarFormatter |
| 5 | + |
| 6 | +x=frange(0,1,.01) |
| 7 | +f=figure(figsize=(6,6)) |
| 8 | +f.text(0.5,0.975,'The old formatter',horizontalalignment='center',verticalalignment='top') |
| 9 | +subplot(221) |
| 10 | +plot(x*1e5+1e10,x*1e-10+1e-5) |
| 11 | +subplot(222) |
| 12 | +plot(x*1e5,x*1e-4) |
| 13 | +subplot(223) |
| 14 | +plot(-x*1e5-1e10,-x*1e-5-1e-10) |
| 15 | +subplot(224) |
| 16 | +plot(-x*1e5,-x*1e-4) |
| 17 | + |
| 18 | +x=frange(0,1,.01) |
| 19 | +f=figure(figsize=(6,6)) |
| 20 | +f.text(0.5,0.975,'The new formatter, default settings',horizontalalignment='center', |
| 21 | + verticalalignment='top') |
| 22 | +subplot(221) |
| 23 | +plot(x*1e5+1e10,x*1e-10+1e-5) |
| 24 | +gca().xaxis.set_major_formatter(NewScalarFormatter()) |
| 25 | +gca().yaxis.set_major_formatter(NewScalarFormatter()) |
| 26 | +subplot(222) |
| 27 | +plot(x*1e5,x*1e-4) |
| 28 | +gca().xaxis.set_major_formatter(NewScalarFormatter()) |
| 29 | +gca().yaxis.set_major_formatter(NewScalarFormatter()) |
| 30 | +subplot(223) |
| 31 | +plot(-x*1e5-1e10,-x*1e-5-1e-10) |
| 32 | +gca().xaxis.set_major_formatter(NewScalarFormatter()) |
| 33 | +gca().yaxis.set_major_formatter(NewScalarFormatter()) |
| 34 | +subplot(224) |
| 35 | +plot(-x*1e5,-x*1e-4) |
| 36 | +gca().xaxis.set_major_formatter(NewScalarFormatter()) |
| 37 | +gca().yaxis.set_major_formatter(NewScalarFormatter()) |
| 38 | + |
| 39 | +x=frange(0,1,.01) |
| 40 | +f=figure(figsize=(6,6)) |
| 41 | +f.text(0.5,0.975,'The new formatter, no numerical offset',horizontalalignment='center', |
| 42 | + verticalalignment='top') |
| 43 | +subplot(221) |
| 44 | +plot(x*1e5+1e10,x*1e-10+1e-5) |
| 45 | +gca().xaxis.set_major_formatter(NewScalarFormatter(useOffset=False)) |
| 46 | +gca().yaxis.set_major_formatter(NewScalarFormatter(useOffset=False)) |
| 47 | +subplot(222) |
| 48 | +plot(x*1e5,x*1e-4) |
| 49 | +gca().xaxis.set_major_formatter(NewScalarFormatter(useOffset=False)) |
| 50 | +gca().yaxis.set_major_formatter(NewScalarFormatter(useOffset=False)) |
| 51 | +subplot(223) |
| 52 | +plot(-x*1e5-1e10,-x*1e-5-1e-10) |
| 53 | +gca().xaxis.set_major_formatter(NewScalarFormatter(useOffset=False)) |
| 54 | +gca().yaxis.set_major_formatter(NewScalarFormatter(useOffset=False)) |
| 55 | +subplot(224) |
| 56 | +plot(-x*1e5,-x*1e-4) |
| 57 | +gca().xaxis.set_major_formatter(NewScalarFormatter(useOffset=False)) |
| 58 | +gca().yaxis.set_major_formatter(NewScalarFormatter(useOffset=False)) |
| 59 | + |
| 60 | +x=frange(0,1,.01) |
| 61 | +f=figure(figsize=(6,6)) |
| 62 | +f.text(0.5,0.975,'The new formatter, with mathtext',horizontalalignment='center', |
| 63 | + verticalalignment='top') |
| 64 | +subplot(221) |
| 65 | +plot(x*1e5+1e10,x*1e-10+1e-5) |
| 66 | +gca().xaxis.set_major_formatter(NewScalarFormatter(useMathText=True)) |
| 67 | +gca().yaxis.set_major_formatter(NewScalarFormatter(useMathText=True)) |
| 68 | +subplot(222) |
| 69 | +plot(x*1e5,x*1e-4) |
| 70 | +gca().xaxis.set_major_formatter(NewScalarFormatter(useMathText=True)) |
| 71 | +gca().yaxis.set_major_formatter(NewScalarFormatter(useMathText=True)) |
| 72 | +subplot(223) |
| 73 | +plot(-x*1e5-1e10,-x*1e-5-1e-10) |
| 74 | +gca().xaxis.set_major_formatter(NewScalarFormatter(useMathText=True)) |
| 75 | +gca().yaxis.set_major_formatter(NewScalarFormatter(useMathText=True)) |
| 76 | +subplot(224) |
| 77 | +plot(-x*1e5,-x*1e-4) |
| 78 | +gca().xaxis.set_major_formatter(NewScalarFormatter(useMathText=True)) |
| 79 | +gca().yaxis.set_major_formatter(NewScalarFormatter(useMathText=True)) |
| 80 | +show() |
0 commit comments