8000 Merge pull request #29420 from meeseeksmachine/auto-backport-of-pr-29… · matplotlib/matplotlib@1a8e664 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1a8e664

Browse files
authored
Merge pull request #29420 from meeseeksmachine/auto-backport-of-pr-29406-on-v3.10.x
Backport PR #29406 on branch v3.10.x (DOC: Update scales overview)
2 parents 19e4d4d + 05ebb73 commit 1a8e664

File tree

2 files changed

+31
-71
lines changed

2 files changed

+31
-71
lines changed

doc/sphinxext/gallery_order.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ def __call__(self, item):
8686
"color_demo",
8787
# pies
8888
"pie_features", "pie_demo2",
89+
# scales
90+
"scales", # Scales overview
8991

9092
# **Plot Types
9193
# Basic

galleries/examples/scales/scales.py

Lines changed: 29 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -5,56 +5,42 @@
55
66
Illustrate the scale transformations applied to axes, e.g. log, symlog, logit.
77
8-
The last two examples are examples of using the ``'function'`` scale by
9-
supplying forward and inverse functions for the scale transformation.
8+
See `matplotlib.scale` for a full list of built-in scales, and
9+
:doc:`/gallery/scales/custom_scale` for how to create your own scale.
1010
"""
1111

1212
import matplotlib.pyplot as plt
1313
import numpy as np
1414

15-
from matplotlib.ticker import FixedLocator, NullFormatter
15+
x = np.arange(400)
16+
y = np.linspace(0.002, 1, 400)
1617

17-
# Fixing random state for reproducibility
18-
np.random.seed(19680801)
19-
20-
# make up some data in the interval ]0, 1[
21-
y = np.random.normal(loc=0.5, scale=0.4, size=1000)
22-
y = y[(y > 0) & (y < 1)]
23-
y.sort()
24-
x = np.arange(len(y))
25-
26-
# plot with various axes scales
2718
fig, axs = plt.subplots(3, 2, figsize=(6, 8), layout='constrained')
2819

29-
# linear
30-
ax = axs[0, 0]
31-
ax.plot(x, y)
32-
ax.set_yscale('linear')
33-
ax.set_title('linear')
34-
ax.grid(True)
35-
20+
axs[0, 0].plot(x, y)
21+
axs[0, 0].set_yscale('linear')
22+
axs[0, 0].set_title('linear')
23+
axs[0, 0].grid(True)
3624

37-
# log
38-
ax = axs[0, 1]
39-
ax.plot(x, y)
40-
ax.set_yscale('log')
41-
ax.set_title('log')
42-
ax.grid(True)
25+
axs[0, 1].plot(x, y)
26+
axs[0, 1].set_yscale('log')
27+
axs[0, 1].set_title('log')
28+
axs[0, 1].grid(True)
4329

30+
axs[1, 0].plot(x, y - y.mean())
31+
axs[1, 0].set_yscale('symlog', linthresh=0.02)
32+
axs[1, 0].set_title('symlog')
33+
axs[1, 0].grid(True)
4434

45-
# symmetric log
46-
ax = axs[1, 1]
47-
ax.plot(x, y - y.mean())
48-
ax.set_yscale('symlog', linthresh=0.02)
49-
ax.set_title('symlog')
50-
ax.grid(True)
35+
axs[1, 1].plot(x, y)
36+
axs[1, 1].set_yscale('logit')
37+
axs[1, 1].set_title('logit')
38+
axs[1, 1].grid(True)
5139

52-
# logit
53-
ax = axs[1, 0]
54-
ax.plot(x, y)
55-
ax.set_yscale('logit')
56-
ax.set_title('logit')
57-
ax.grid(True)
40+
axs[2, 0].plot(x, y - y.mean())
41+
axs[2, 0].set_yscale('asinh', linear_width=0.01)
42+
axs[2, 0].set_title('asinh')
43+
axs[2, 0].grid(True)
5844

5945

6046
# Function x**(1/2)
@@ -66,38 +52,11 @@ def inverse(x):
6652
return x**2
6753

6854

69-
ax = axs[2, 0]
70-
ax.plot(x, y)
71-
ax.set_yscale('function', functions=(forward, inverse))
72-
ax.set_title('function: $x^{1/2}$')
73-
ax.grid(True)
74-
ax.yaxis.set_major_locator(FixedLocator(np.arange(0, 1, 0.2)**2))
75-
ax.yaxis.set_major_locator(FixedLocator(np.arange(0, 1, 0.2)))
76-
77-
78-
# Function Mercator transform
79-
def forward(a):
80-
a = np.deg2rad(a)
81-
return np.rad2deg(np.log(np.abs(np.tan(a) + 1.0 / np.cos(a))))
82-
83-
84-
def inverse(a):
85-
a = np.deg2rad(a)
86-
return np.rad2deg(np.arctan(np.sinh(a)))
87-
88-
ax = axs[2, 1]
89-
90-
t = np.arange(0, 170.0, 0.1)
91-
s = t / 2.
92-
93-
ax.plot(t, s, '-', lw=2)
94-
95-
ax.set_yscale('function', functions=(forward, inverse))
96-
ax.set_title('function: Mercator')
97-
ax.grid(True)
98-
ax.set_xlim([0, 180])
99-
ax.yaxis.set_minor_formatter(NullFormatter())
100-
ax.yaxis.set_major_locator(FixedLocator(np.arange(0, 90, 10)))
55+
axs[2, 1].plot(x, y)
56+
axs[2, 1].set_yscale('function', functions=(forward, inverse))
57+
axs[2, 1].set_title('function: $x^{1/2}$')
58+
axs[2, 1].grid(True)
59+
axs[2, 1].set_yticks(np.arange(0, 1.2, 0.2))
10160

10261
plt.show()
10362

@@ -110,7 +69,6 @@ def inverse(a):
11069
#
11170
# - `matplotlib.axes.Axes.set_xscale`
11271
# - `matplotlib.axes.Axes.set_yscale`
113-
# - `matplotlib.axis.Axis.set_major_locator`
11472
# - `matplotlib.scale.LinearScale`
11573
# - `matplotlib.scale.LogScale`
11674
# - `matplotlib.scale.SymmetricalLogScale`

0 commit comments

Comments
 (0)
0