From 6e932aa5f09b6b28f5c707e1019f07bc29b5b5d6 Mon Sep 17 00:00:00 2001 From: Eric Ma Date: Fri, 31 Jul 2015 23:00:58 -0400 Subject: [PATCH 1/6] mep12 on newscalarformatter_demo.py --- .../pylab_examples/newscalarformatter_demo.py | 148 +++++++++--------- 1 file changed, 74 insertions(+), 74 deletions(-) diff --git a/examples/pylab_examples/newscalarformatter_demo.py b/examples/pylab_examples/newscalarformatter_demo.py index c91a938386d9..460462a2f248 100644 --- a/examples/pylab_examples/newscalarformatter_demo.py +++ b/examples/pylab_examples/newscalarformatter_demo.py @@ -1,88 +1,88 @@ -#!/usr/bin/env python -# Demonstrating the improvements and options of the proposed new ScalarFormatter -from pylab import * -from matplotlib.ticker import OldScalarFormatter +# from pylab import * +import matplotlib.pyplot as plt +import numpy as np +from matplotlib.ticker import OldScalarFormatter, ScalarFormatter -x = frange(0, 1, .01) -f = figure(figsize=(6, 6)) +x = np.arange(0, 1, .01) +f = plt.figure(figsize=(6, 6)) f.text(0.5, 0.975, 'The old formatter', horizontalalignment='center', verticalalignment='top') -subplot(221) -plot(x*1e5 + 1e10, x*1e-10 + 1e-5) -gca().xaxis.set_major_formatter(OldScalarFormatter()) -gca().yaxis.set_major_formatter(OldScalarFormatter()) -subplot(222) -plot(x*1e5, x*1e-4) -gca().xaxis.set_major_formatter(OldScalarFormatter()) -gca().yaxis.set_major_formatter(OldScalarFormatter()) -subplot(223) -plot(-x*1e5 - 1e10, -x*1e-5 - 1e-10) -gca().xaxis.set_major_formatter(OldScalarFormatter()) -gca().yaxis.set_major_formatter(OldScalarFormatter()) -subplot(224) -plot(-x*1e5, -x*1e-4) -gca().xaxis.set_major_formatter(OldScalarFormatter()) -gca().yaxis.set_major_formatter(OldScalarFormatter()) +plt.subplot(221) +plt.plot(x*1e5 + 1e10, x*1e-10 + 1e-5) +plt.gca().xaxis.set_major_formatter(OldScalarFormatter()) +plt.gca().yaxis.set_major_formatter(OldScalarFormatter()) +plt.subplot(222) +plt.plot(x*1e5, x*1e-4) +plt.gca().xaxis.set_major_formatter(OldScalarFormatter()) +plt.gca().yaxis.set_major_formatter(OldScalarFormatter()) +plt.subplot(223) +plt.plot(-x*1e5 - 1e10, -x*1e-5 - 1e-10) +plt.gca().xaxis.set_major_formatter(OldScalarFormatter()) +plt.gca().yaxis.set_major_formatter(OldScalarFormatter()) +plt.subplot(224) +plt.plot(-x*1e5, -x*1e-4) +plt.gca().xaxis.set_major_formatter(OldScalarFormatter()) +plt.gca().yaxis.set_major_formatter(OldScalarFormatter()) -x = frange(0, 1, .01) +x = np.arange(0, 1, .01) f = figure(figsize=(6, 6)) f.text(0.5, 0.975, 'The new formatter, default settings', horizontalalignment='center', verticalalignment='top') -subplot(221) -plot(x*1e5 + 1e10, x*1e-10 + 1e-5) -gca().xaxis.set_major_formatter(ScalarFormatter()) -gca().yaxis.set_major_formatter(ScalarFormatter()) -subplot(222) -plot(x*1e5, x*1e-4) -gca().xaxis.set_major_formatter(ScalarFormatter()) -gca().yaxis.set_major_formatter(ScalarFormatter()) -subplot(223) -plot(-x*1e5 - 1e10, -x*1e-5 - 1e-10) -gca().xaxis.set_major_formatter(ScalarFormatter()) -gca().yaxis.set_major_formatter(ScalarFormatter()) -subplot(224) -plot(-x*1e5, -x*1e-4) -gca().xaxis.set_major_formatter(ScalarFormatter()) -gca().yaxis.set_major_formatter(ScalarFormatter()) +plt.subplot(221) +plt.plot(x*1e5 + 1e10, x*1e-10 + 1e-5) +plt.gca().xaxis.set_major_formatter(ScalarFormatter()) +plt.gca().yaxis.set_major_formatter(ScalarFormatter()) +plt.subplot(222) +plt.plot(x*1e5, x*1e-4) +plt.gca().xaxis.set_major_formatter(ScalarFormatter()) +plt.gca().yaxis.set_major_formatter(ScalarFormatter()) +plt.subplot(223) +plt.plot(-x*1e5 - 1e10, -x*1e-5 - 1e-10) +plt.gca().xaxis.set_major_formatter(ScalarFormatter()) +plt.gca().yaxis.set_major_formatter(ScalarFormatter()) +plt.subplot(224) +plt.plot(-x*1e5, -x*1e-4) +plt.gca().xaxis.set_major_formatter(ScalarFormatter()) +plt.gca().yaxis.set_major_formatter(ScalarFormatter()) -x = frange(0, 1, .01) +x = np.arange(0, 1, .01) f = figure(figsize=(6, 6)) f.text(0.5, 0.975, 'The new formatter, no numerical offset', horizontalalignment='center', verticalalignment='top') -subplot(221) -plot(x*1e5 + 1e10, x*1e-10 + 1e-5) -gca().xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) -gca().yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) -subplot(222) -plot(x*1e5, x*1e-4) -gca().xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) -gca().yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) -subplot(223) -plot(-x*1e5 - 1e10, -x*1e-5 - 1e-10) -gca().xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) -gca().yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) -subplot(224) -plot(-x*1e5, -x*1e-4) -gca().xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) -gca().yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) +plt.subplot(221) +plt.plot(x*1e5 + 1e10, x*1e-10 + 1e-5) +plt.gca().xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) +plt.gca().yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) +plt.subplot(222) +plt.plot(x*1e5, x*1e-4) +plt.gca().xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) +plt.gca().yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) +plt.subplot(223) +plt.plot(-x*1e5 - 1e10, -x*1e-5 - 1e-10) +plt.gca().xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) +plt.gca().yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) +plt.subplot(224) +plt.plot(-x*1e5, -x*1e-4) +plt.gca().xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) +plt.gca().yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) -x = frange(0, 1, .01) +x = np.arange(0, 1, .01) f = figure(figsize=(6, 6)) f.text(0.5, 0.975, 'The new formatter, with mathtext', horizontalalignment='center', verticalalignment='top') -subplot(221) -plot(x*1e5 + 1e10, x*1e-10 + 1e-5) -gca().xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) -gca().yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) -subplot(222) -plot(x*1e5, x*1e-4) -gca().xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) -gca().yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) -subplot(223) -plot(-x*1e5 - 1e10, -x*1e-5 - 1e-10) -gca().xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) -gca().yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) -subplot(224) -plot(-x*1e5, -x*1e-4) -gca().xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) -gca().yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) -show() +plt.subplot(221) +plt.plot(x*1e5 + 1e10, x*1e-10 + 1e-5) +plt.gca().xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) +plt.gca().yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) +plt.subplot(222) +plt.plot(x*1e5, x*1e-4) +plt.gca().xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) +plt.gca().yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) +plt.subplot(223) +plt.plot(-x*1e5 - 1e10, -x*1e-5 - 1e-10) +plt.gca().xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) +plt.gca().yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) +plt.subplot(224) +plt.plot(-x*1e5, -x*1e-4) +plt.gca().xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) +plt.gca().yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) +plt.show() From 149fabde1931ad6108b5bb13eadd50c0c63dd975 Mon Sep 17 00:00:00 2001 From: Eric Ma Date: Fri, 31 Jul 2015 23:02:28 -0400 Subject: [PATCH 2/6] pep8 changes on newscalarformatter_demo.py --- .../pylab_examples/newscalarformatter_demo.py | 48 ++++++++++--------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/examples/pylab_examples/newscalarformatter_demo.py b/examples/pylab_examples/newscalarformatter_demo.py index 460462a2f248..fdde94f29339 100644 --- a/examples/pylab_examples/newscalarformatter_demo.py +++ b/examples/pylab_examples/newscalarformatter_demo.py @@ -1,88 +1,92 @@ # from pylab import * -import matplotlib.pyplot as plt -import numpy as np +import matplotlib.pyplot as plt +import numpy as np from matplotlib.ticker import OldScalarFormatter, ScalarFormatter x = np.arange(0, 1, .01) f = plt.figure(figsize=(6, 6)) -f.text(0.5, 0.975, 'The old formatter', horizontalalignment='center', verticalalignment='top') +f.text(0.5, 0.975, 'The old formatter', + horizontalalignment='center', verticalalignment='top') plt.subplot(221) -plt.plot(x*1e5 + 1e10, x*1e-10 + 1e-5) +plt.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5) plt.gca().xaxis.set_major_formatter(OldScalarFormatter()) plt.gca().yaxis.set_major_formatter(OldScalarFormatter()) plt.subplot(222) -plt.plot(x*1e5, x*1e-4) +plt.plot(x * 1e5, x * 1e-4) plt.gca().xaxis.set_major_formatter(OldScalarFormatter()) plt.gca().yaxis.set_major_formatter(OldScalarFormatter()) plt.subplot(223) -plt.plot(-x*1e5 - 1e10, -x*1e-5 - 1e-10) +plt.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10) plt.gca().xaxis.set_major_formatter(OldScalarFormatter()) plt.gca().yaxis.set_major_formatter(OldScalarFormatter()) plt.subplot(224) -plt.plot(-x*1e5, -x*1e-4) +plt.plot(-x * 1e5, -x * 1e-4) plt.gca().xaxis.set_major_formatter(OldScalarFormatter()) plt.gca().yaxis.set_major_formatter(OldScalarFormatter()) x = np.arange(0, 1, .01) f = figure(figsize=(6, 6)) -f.text(0.5, 0.975, 'The new formatter, default settings', horizontalalignment='center', +f.text(0.5, 0.975, 'The new formatter, default settings', + horizontalalignment='center', verticalalignment='top') plt.subplot(221) -plt.plot(x*1e5 + 1e10, x*1e-10 + 1e-5) +plt.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5) plt.gca().xaxis.set_major_formatter(ScalarFormatter()) plt.gca().yaxis.set_major_formatter(ScalarFormatter()) plt.subplot(222) -plt.plot(x*1e5, x*1e-4) +plt.plot(x * 1e5, x * 1e-4) plt.gca().xaxis.set_major_formatter(ScalarFormatter()) plt.gca().yaxis.set_major_formatter(ScalarFormatter()) plt.subplot(223) -plt.plot(-x*1e5 - 1e10, -x*1e-5 - 1e-10) +plt.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10) plt.gca().xaxis.set_major_formatter(ScalarFormatter()) plt.gca().yaxis.set_major_formatter(ScalarFormatter()) plt.subplot(224) -plt.plot(-x*1e5, -x*1e-4) +plt.plot(-x * 1e5, -x * 1e-4) plt.gca().xaxis.set_major_formatter(ScalarFormatter()) plt.gca().yaxis.set_major_formatter(ScalarFormatter()) x = np.arange(0, 1, .01) f = figure(figsize=(6, 6)) -f.text(0.5, 0.975, 'The new formatter, no numerical offset', horizontalalignment='center', +f.text(0.5, 0.975, 'The new formatter, no numerical offset', + horizontalalignment='center', verticalalignment='top') plt.subplot(221) -plt.plot(x*1e5 + 1e10, x*1e-10 + 1e-5) +plt.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5) plt.gca().xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) plt.gca().yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) plt.subplot(222) -plt.plot(x*1e5, x*1e-4) +plt.plot(x * 1e5, x * 1e-4) plt.gca().xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) plt.gca().yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) plt.subplot(223) -plt.plot(-x*1e5 - 1e10, -x*1e-5 - 1e-10) +plt.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10) plt.gca().xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) plt.gca().yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) plt.subplot(224) -plt.plot(-x*1e5, -x*1e-4) +plt.plot(-x * 1e5, -x * 1e-4) plt.gca().xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) plt.gca().yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) x = np.arange(0, 1, .01) f = figure(figsize=(6, 6)) -f.text(0.5, 0.975, 'The new formatter, with mathtext', horizontalalignment='center', +f.text(0.5, 0.975, 'The new formatter, with mathtext', + horizontalalignment='center', verticalalignment='top') plt.subplot(221) -plt.plot(x*1e5 + 1e10, x*1e-10 + 1e-5) +plt.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5) plt.gca().xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) plt.gca().yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) plt.subplot(222) -plt.plot(x*1e5, x*1e-4) +plt.plot(x * 1e5, x * 1e-4) plt.gca().xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) plt.gca().yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) plt.subplot(223) -plt.plot(-x*1e5 - 1e10, -x*1e-5 - 1e-10) +plt.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10) plt.gca().xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) plt.gca().yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) plt.subplot(224) -plt.plot(-x*1e5, -x*1e-4) +plt.plot(-x * 1e5, -x * 1e-4) plt.gca().xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) plt.gca().yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) plt.show() From ddfe342d7a775b7c93d6da7c6393e446bea89783 Mon Sep 17 00:00:00 2001 From: Eric Ma Date: Fri, 31 Jul 2015 23:11:16 -0400 Subject: [PATCH 3/6] reworked code to make it easier to read --- .../pylab_examples/newscalarformatter_demo.py | 106 ++++++++++++------ 1 file changed, 70 insertions(+), 36 deletions(-) diff --git a/examples/pylab_examples/newscalarformatter_demo.py b/examples/pylab_examples/newscalarformatter_demo.py index fdde94f29339..534e77ed40e6 100644 --- a/examples/pylab_examples/newscalarformatter_demo.py +++ b/examples/pylab_examples/newscalarformatter_demo.py @@ -1,92 +1,126 @@ -# from pylab import * import matplotlib.pyplot as plt import numpy as np from matplotlib.ticker import OldScalarFormatter, ScalarFormatter +## Example 1 ## x = np.arange(0, 1, .01) f = plt.figure(figsize=(6, 6)) f.text(0.5, 0.975, 'The old formatter', horizontalalignment='center', verticalalignment='top') + plt.subplot(221) plt.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5) -plt.gca().xaxis.set_major_formatter(OldScalarFormatter()) -plt.gca().yaxis.set_major_formatter(OldScalarFormatter()) +ax1 = plt.gca() +ax1.xaxis.set_major_formatter(OldScalarFormatter()) +ax1.yaxis.set_major_formatter(OldScalarFormatter()) + plt.subplot(222) plt.plot(x * 1e5, x * 1e-4) -plt.gca().xaxis.set_major_formatter(OldScalarFormatter()) -plt.gca().yaxis.set_major_formatter(OldScalarFormatter()) +ax2 = plt.gca() +ax2.xaxis.set_major_formatter(OldScalarFormatter()) +ax2.yaxis.set_major_formatter(OldScalarFormatter()) + plt.subplot(223) plt.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10) -plt.gca().xaxis.set_major_formatter(OldScalarFormatter()) -plt.gca().yaxis.set_major_formatter(OldScalarFormatter()) +ax3 = plt.gca() +ax3.xaxis.set_major_formatter(OldScalarFormatter()) +ax3.yaxis.set_major_formatter(OldScalarFormatter()) + plt.subplot(224) plt.plot(-x * 1e5, -x * 1e-4) -plt.gca().xaxis.set_major_formatter(OldScalarFormatter()) -plt.gca().yaxis.set_major_formatter(OldScalarFormatter()) +ax4 = plt.gca() +ax4.xaxis.set_major_formatter(OldScalarFormatter()) +ax4.yaxis.set_major_formatter(OldScalarFormatter()) +## Example 2 ## x = np.arange(0, 1, .01) -f = figure(figsize=(6, 6)) +f = plt.figure(figsize=(6, 6)) f.text(0.5, 0.975, 'The new formatter, default settings', horizontalalignment='center', verticalalignment='top') + plt.subplot(221) plt.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5) -plt.gca().xaxis.set_major_formatter(ScalarFormatter()) -plt.gca().yaxis.set_major_formatter(ScalarFormatter()) +ax1 = plt.gca() +ax1.xaxis.set_major_formatter(ScalarFormatter()) +ax1.yaxis.set_major_formatter(ScalarFormatter()) + plt.subplot(222) plt.plot(x * 1e5, x * 1e-4) -plt.gca().xaxis.set_major_formatter(ScalarFormatter()) -plt.gca().yaxis.set_major_formatter(ScalarFormatter()) +ax2 = plt.gca() +ax2.xaxis.set_major_formatter(ScalarFormatter()) +ax2.yaxis.set_major_formatter(ScalarFormatter()) + plt.subplot(223) plt.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10) -plt.gca().xaxis.set_major_formatter(ScalarFormatter()) -plt.gca().yaxis.set_major_formatter(ScalarFormatter()) +ax3 = plt.gca() +ax3.xaxis.set_major_formatter(ScalarFormatter()) +ax3.yaxis.set_major_formatter(ScalarFormatter()) + plt.subplot(224) plt.plot(-x * 1e5, -x * 1e-4) -plt.gca().xaxis.set_major_formatter(ScalarFormatter()) -plt.gca().yaxis.set_major_formatter(ScalarFormatter()) +ax4 = plt.gca() +ax4.xaxis.set_major_formatter(ScalarFormatter()) +ax4.yaxis.set_major_formatter(ScalarFormatter()) +## Example 3 ## x = np.arange(0, 1, .01) -f = figure(figsize=(6, 6)) +f = plt.figure(figsize=(6, 6)) f.text(0.5, 0.975, 'The new formatter, no numerical offset', horizontalalignment='center', verticalalignment='top') + plt.subplot(221) plt.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5) -plt.gca().xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) -plt.gca().yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) +ax1 = plt.gca() +ax1.xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) +ax1.yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) + plt.subplot(222) plt.plot(x * 1e5, x * 1e-4) -plt.gca().xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) -plt.gca().yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) +ax2 = plt.gca() +ax2.xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) +ax2.yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) + plt.subplot(223) plt.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10) -plt.gca().xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) -plt.gca().yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) +ax3 = plt.gca() +ax3.xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) +ax3.yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) + plt.subplot(224) plt.plot(-x * 1e5, -x * 1e-4) -plt.gca().xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) -plt.gca().yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) +ax4 = plt.gca() +ax4.xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) +ax4.yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) +## Example 4 ## x = np.arange(0, 1, .01) -f = figure(figsize=(6, 6)) +f = plt.figure(figsize=(6, 6)) f.text(0.5, 0.975, 'The new formatter, with mathtext', horizontalalignment='center', verticalalignment='top') plt.subplot(221) plt.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5) -plt.gca().xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) -plt.gca().yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) +ax1 = plt.gca() +ax1.xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) +ax1.yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) + plt.subplot(222) plt.plot(x * 1e5, x * 1e-4) -plt.gca().xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) -plt.gca().yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) +ax2 = plt.gca() +ax2.xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) +ax2.yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) + plt.subplot(223) plt.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10) -plt.gca().xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) -plt.gca().yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) +ax3 = plt.gca() +ax3.xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) +ax3.yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) + plt.subplot(224) plt.plot(-x * 1e5, -x * 1e-4) -plt.gca().xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) -plt.gca().yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) +ax4 = plt.gca() +ax4.xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) +ax4.yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) plt.show() From e35dc8911ca1ba2deef47b4f4de25af3d75e9029 Mon Sep 17 00:00:00 2001 From: Eric Ma Date: Fri, 31 Jul 2015 23:16:54 -0400 Subject: [PATCH 4/6] restructured fig and axes --- .../pylab_examples/newscalarformatter_demo.py | 81 ++++++------------- 1 file changed, 25 insertions(+), 56 deletions(-) diff --git a/examples/pylab_examples/newscalarformatter_demo.py b/examples/pylab_examples/newscalarformatter_demo.py index 534e77ed40e6..c35426ecdb3d 100644 --- a/examples/pylab_examples/newscalarformatter_demo.py +++ b/examples/pylab_examples/newscalarformatter_demo.py @@ -4,123 +4,92 @@ ## Example 1 ## x = np.arange(0, 1, .01) -f = plt.figure(figsize=(6, 6)) -f.text(0.5, 0.975, 'The old formatter', +fig, [[ax1, ax2], [ax3, ax4]] = plt.subplots(2, 2, figsize=(6, 6)) +fig.text(0.5, 0.975, 'The old formatter', horizontalalignment='center', verticalalignment='top') - -plt.subplot(221) -plt.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5) -ax1 = plt.gca() +ax1.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5) ax1.xaxis.set_major_formatter(OldScalarFormatter()) ax1.yaxis.set_major_formatter(OldScalarFormatter()) -plt.subplot(222) -plt.plot(x * 1e5, x * 1e-4) -ax2 = plt.gca() +ax2.plot(x * 1e5, x * 1e-4) ax2.xaxis.set_major_formatter(OldScalarFormatter()) ax2.yaxis.set_major_formatter(OldScalarFormatter()) -plt.subplot(223) -plt.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10) -ax3 = plt.gca() +ax3.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10) ax3.xaxis.set_major_formatter(OldScalarFormatter()) ax3.yaxis.set_major_formatter(OldScalarFormatter()) -plt.subplot(224) -plt.plot(-x * 1e5, -x * 1e-4) +ax4.plot(-x * 1e5, -x * 1e-4) ax4 = plt.gca() ax4.xaxis.set_major_formatter(OldScalarFormatter()) ax4.yaxis.set_major_formatter(OldScalarFormatter()) ## Example 2 ## x = np.arange(0, 1, .01) -f = plt.figure(figsize=(6, 6)) -f.text(0.5, 0.975, 'The new formatter, default settings', +fig, [[ax1, ax2], [ax3, ax4]] = plt.subplots(2, 2, figsize=(6, 6)) +fig.text(0.5, 0.975, 'The new formatter, default settings', horizontalalignment='center', verticalalignment='top') -plt.subplot(221) -plt.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5) -ax1 = plt.gca() +ax1.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5) ax1.xaxis.set_major_formatter(ScalarFormatter()) ax1.yaxis.set_major_formatter(ScalarFormatter()) -plt.subplot(222) -plt.plot(x * 1e5, x * 1e-4) -ax2 = plt.gca() +ax2.plot(x * 1e5, x * 1e-4) ax2.xaxis.set_major_formatter(ScalarFormatter()) ax2.yaxis.set_major_formatter(ScalarFormatter()) -plt.subplot(223) -plt.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10) -ax3 = plt.gca() +ax3.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10) ax3.xaxis.set_major_formatter(ScalarFormatter()) ax3.yaxis.set_major_formatter(ScalarFormatter()) -plt.subplot(224) -plt.plot(-x * 1e5, -x * 1e-4) -ax4 = plt.gca() +ax4.plot(-x * 1e5, -x * 1e-4) ax4.xaxis.set_major_formatter(ScalarFormatter()) ax4.yaxis.set_major_formatter(ScalarFormatter()) ## Example 3 ## x = np.arange(0, 1, .01) -f = plt.figure(figsize=(6, 6)) -f.text(0.5, 0.975, 'The new formatter, no numerical offset', +fig, [[ax1, ax2], [ax3, ax4]] = plt.subplots(2, 2, figsize=(6, 6)) +fig.text(0.5, 0.975, 'The new formatter, no numerical offset', horizontalalignment='center', verticalalignment='top') -plt.subplot(221) -plt.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5) -ax1 = plt.gca() +ax1.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5) ax1.xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) ax1.yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) -plt.subplot(222) -plt.plot(x * 1e5, x * 1e-4) -ax2 = plt.gca() +ax2.plot(x * 1e5, x * 1e-4) ax2.xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) ax2.yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) -plt.subplot(223) -plt.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10) -ax3 = plt.gca() +ax3.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10) ax3.xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) ax3.yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) -plt.subplot(224) -plt.plot(-x * 1e5, -x * 1e-4) -ax4 = plt.gca() +ax4.plot(-x * 1e5, -x * 1e-4) ax4.xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) ax4.yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) ## Example 4 ## x = np.arange(0, 1, .01) -f = plt.figure(figsize=(6, 6)) -f.text(0.5, 0.975, 'The new formatter, with mathtext', +fig, [[ax1, ax2], [ax3, ax4]] = plt.subplots(2, 2, figsize=(6, 6)) +fig.text(0.5, 0.975, 'The new formatter, with mathtext', horizontalalignment='center', verticalalignment='top') -plt.subplot(221) -plt.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5) -ax1 = plt.gca() + +ax1.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5) ax1.xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) ax1.yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) -plt.subplot(222) -plt.plot(x * 1e5, x * 1e-4) -ax2 = plt.gca() +ax2.plot(x * 1e5, x * 1e-4) ax2.xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) ax2.yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) -plt.subplot(223) -plt.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10) -ax3 = plt.gca() +ax3.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10) ax3.xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) ax3.yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) -plt.subplot(224) -plt.plot(-x * 1e5, -x * 1e-4) -ax4 = plt.gca() +ax4.plot(-x * 1e5, -x * 1e-4) ax4.xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) ax4.yaxis.set_major_formatter(ScalarFormatter(useMathText=True)) plt.show() From 5db81550fb3b02dc57c65c3ac256d00a47b3cf24 Mon Sep 17 00:00:00 2001 From: Eric Ma Date: Fri, 31 Jul 2015 23:22:11 -0400 Subject: [PATCH 5/6] pep8 changes --- .../pylab_examples/newscalarformatter_demo.py | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/examples/pylab_examples/newscalarformatter_demo.py b/examples/pylab_examples/newscalarformatter_demo.py index c35426ecdb3d..15905e3f0a24 100644 --- a/examples/pylab_examples/newscalarformatter_demo.py +++ b/examples/pylab_examples/newscalarformatter_demo.py @@ -2,11 +2,11 @@ import numpy as np from matplotlib.ticker import OldScalarFormatter, ScalarFormatter -## Example 1 ## +# Example 1 x = np.arange(0, 1, .01) fig, [[ax1, ax2], [ax3, ax4]] = plt.subplots(2, 2, figsize=(6, 6)) fig.text(0.5, 0.975, 'The old formatter', - horizontalalignment='center', verticalalignment='top') + horizontalalignment='center', verticalalignment='top') ax1.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5) ax1.xaxis.set_major_formatter(OldScalarFormatter()) ax1.yaxis.set_major_formatter(OldScalarFormatter()) @@ -24,12 +24,12 @@ ax4.xaxis.set_major_formatter(OldScalarFormatter()) ax4.yaxis.set_major_formatter(OldScalarFormatter()) -## Example 2 ## +# Example 2 x = np.arange(0, 1, .01) fig, [[ax1, ax2], [ax3, ax4]] = plt.subplots(2, 2, figsize=(6, 6)) fig.text(0.5, 0.975, 'The new formatter, default settings', - horizontalalignment='center', - verticalalignment='top') + horizontalalignment='center', + verticalalignment='top') ax1.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5) ax1.xaxis.set_major_formatter(ScalarFormatter()) @@ -47,12 +47,12 @@ ax4.xaxis.set_major_formatter(ScalarFormatter()) ax4.yaxis.set_major_formatter(ScalarFormatter()) -## Example 3 ## +# Example 3 x = np.arange(0, 1, .01) fig, [[ax1, ax2], [ax3, ax4]] = plt.subplots(2, 2, figsize=(6, 6)) fig.text(0.5, 0.975, 'The new formatter, no numerical offset', - horizontalalignment='center', - verticalalignment='top') + horizontalalignment='center', + verticalalignment='top') ax1.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5) ax1.xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) @@ -70,12 +70,12 @@ ax4.xaxis.set_major_formatter(ScalarFormatter(useOffset=False)) ax4.yaxis.set_major_formatter(ScalarFormatter(useOffset=False)) -## Example 4 ## +# Example 4 x = np.arange(0, 1, .01) fig, [[ax1, ax2], [ax3, ax4]] = plt.subplots(2, 2, figsize=(6, 6)) fig.text(0.5, 0.975, 'The new formatter, with mathtext', - horizontalalignment='center', - verticalalignment='top') + horizontalalignment='center', + verticalalignment='top') ax1.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5) ax1.xaxis.set_major_formatter(ScalarFormatter(useMathText=True)) From b8f3e647b15ca77c8cebbe84f47f5ffe96bcd1af Mon Sep 17 00:00:00 2001 From: Eric Ma Date: Sat, 1 Aug 2015 07:50:04 -0400 Subject: [PATCH 6/6] removed extraneous .gca() --- examples/pylab_examples/newscalarformatter_demo.py | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/pylab_examples/newscalarformatter_demo.py b/examples/pylab_examples/newscalarformatter_demo.py index 15905e3f0a24..1e525ad8cb6e 100644 --- a/examples/pylab_examples/newscalarformatter_demo.py +++ b/examples/pylab_examples/newscalarformatter_demo.py @@ -20,7 +20,6 @@ ax3.yaxis.set_major_formatter(OldScalarFormatter()) ax4.plot(-x * 1e5, -x * 1e-4) -ax4 = plt.gca() ax4.xaxis.set_major_formatter(OldScalarFormatter()) ax4.yaxis.set_major_formatter(OldScalarFormatter())