Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bd47d3d

Browse filesBrowse files
committed
Cleanup scalarformatter.py example.
Move everything to a single figure for better comparability and remove repeated code.
1 parent ffd3b12 commit bd47d3d
Copy full SHA for bd47d3d

File tree

Expand file treeCollapse file tree

1 file changed

+25
-71
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+25
-71
lines changed

‎galleries/examples/ticks/scalarformatter.py

Copy file name to clipboardExpand all lines: galleries/examples/ticks/scalarformatter.py
+25-71Lines changed: 25 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -3,82 +3,36 @@
33
The default tick formatter
44
==========================
55
6-
The example shows use of the default `.ScalarFormatter` with different
7-
settings.
8-
9-
Example 1 : Default
10-
11-
Example 2 : With no Numerical Offset
12-
13-
Example 3 : With Mathtext
6+
By default, tick labels are formatted using a `.ScalarFormatter`, which can be
7+
configured via `~.axes.Axes.ticklabel_format`. This example illustrates some
8+
possible configurations:
9+
10+
- Default.
11+
- ``useMathText=True``: Fancy formatting of mathematical expressions.
12+
- ``useOffset=False``: Do not use offset notation; see
13+
`.ScalarFormatter.set_useOffset`.
1414
"""
1515

1616
import matplotlib.pyplot as plt
1717
import numpy as np
1818

19-
# %%
20-
# Example 1
21-
2219
x = np.arange(0, 1, .01)
23-
fig, [[ax1, ax2], [ax3, ax4]] = plt.subplots(2, 2, figsize=(6, 6))
24-
fig.text(0.5, 0.975, 'Default settings',
25-
horizontalalignment='center',
26-
verticalalignment='top')
27-
28-
ax1.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5)
29-
30-
ax2.plot(x * 1e5, x * 1e-4)
31-
32-
ax3.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10)
33-
34-
ax4.plot(-x * 1e5, -x * 1e-4)
35-
36-
fig.subplots_adjust(wspace=0.7, hspace=0.6)
37-
38-
# %%
39-
# Example 2
40-
41-
x = np.arange(0, 1, .01)
42-
fig, [[ax1, ax2], [ax3, ax4]] = plt.subplots(2, 2, figsize=(6, 6))
43-
fig.text(0.5, 0.975, 'No numerical offset',
44-
horizontalalignment='center',
45-
verticalalignment='top')
46-
47-
ax1.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5)
48-
ax1.ticklabel_format(useOffset=False)
49-
50-
ax2.plot(x * 1e5, x * 1e-4)
51-
ax2.ticklabel_format(useOffset=False)
52-
53-
ax3.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10)
54-
ax3.ticklabel_format(useOffset=False)
55-
56-
ax4.plot(-x * 1e5, -x * 1e-4)
57-
ax4.ticklabel_format(useOffset=False)
58-
59-
fig.subplots_adjust(wspace=0.7, hspace=0.6)
60-
61-
# %%
62-
# Example 3
63-
64-
x = np.arange(0, 1, .01)
65-
fig, [[ax1, ax2], [ax3, ax4]] = plt.subplots(2, 2, figsize=(6, 6))
66-
fig.text(0.5, 0.975, 'With mathtext',
67-
horizontalalignment='center',
68-
verticalalignment='top')
69-
70-
ax1.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5)
71-
ax1.ticklabel_format(useMathText=True)
72-
73-
ax2.plot(x * 1e5, x * 1e-4)
74-
ax2.ticklabel_format(useMathText=True)
75-
76-
ax3.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10)
77-
ax3.ticklabel_format(useMathText=True)
78-
79-
ax4.plot(-x * 1e5, -x * 1e-4)
80-
ax4.ticklabel_format(useMathText=True)
81-
82-
fig.subplots_adjust(wspace=0.7, hspace=0.6)
20+
fig, axs = plt.subplots(
21+
3, 3, figsize=(9, 9), layout="constrained", gridspec_kw={"hspace": 0.1})
22+
23+
for col in axs.T:
24+
col[0].plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5)
25+
col[1].plot(x * 1e5, x * 1e-4)
26+
col[2].plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10)
27+
28+
for ax in axs[:, 1]:
29+
ax.ticklabel_format(useMathText=True)
30+
for ax in axs[:, 2]:
31+
ax.ticklabel_format(useOffset=False)
32+
33+
plt.rcParams.update({"axes.titleweight": "bold", "axes.titley": 1.1})
34+
axs[0, 0].set_title("default settings")
35+
axs[0, 1].set_title("useMathText=True")
36+
axs[0, 2].set_title("useOffset=False")
8337

8438
plt.show()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.