Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Mep12 newscalarformatter demo.py #4848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 3, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
restructured fig and axes
  • Loading branch information
ericmjl committed Aug 1, 2015
commit e35dc8911ca1ba2deef47b4f4de25af3d75e9029
81 changes: 25 additions & 56 deletions examples/pylab_examples/newscalarformatter_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really need gca() here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is just a leftover from commit e35dc89

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, my bad!

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()