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

Skip to content

Commit 784c759

Browse files
committed
Prefer geomspace() to logspace().
geomspace() ("geometric progression from `a` to `b`") is, I think, easier to read than logspace ("geometric progression from `10**a` to `10**b`") -- see eg changes in ticker.py, colorbar.py.
1 parent 85a96fb commit 784c759

4 files changed

Lines changed: 5 additions & 6 deletions

File tree

examples/text_labels_and_annotations/custom_legends.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
np.random.seed(19680801)
2828

2929
N = 10
30-
data = np.transpose([np.logspace(0, 1, 100) + np.random.randn(100) + ii
31-
for ii in range(N)])
30+
data = (np.geomspace(1, 10, 100) + np.random.randn(N, 100)).T
3231
cmap = plt.cm.coolwarm
3332
rcParams['axes.prop_cycle'] = cycler(color=cmap(np.linspace(0, 1, N)))
3433

lib/matplotlib/ticker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ def set_locs(self, locs=None):
968968
# Add labels between bases at log-spaced coefficients;
969969
# include base powers in case the locations include
970970
# "major" and "minor" points, as in colorbar.
971-
c = np.logspace(0, 1, int(b)//2 + 1, base=b)
971+
c = np.geomspace(1, b, int(b)//2 + 1)
972972
self._sublabels = set(np.round(c))
973973
# For base 10, this yields (1, 2, 3, 4, 6, 10).
974974
else:

lib/mpl_toolkits/axes_grid1/colorbar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ def _uniform_y(self, N):
634634
"""
635635
vmin, vmax = self._get_colorbar_limits()
636636
if isinstance(self.norm, colors.LogNorm):
637-
y = np.logspace(np.log10(vmin), np.log10(vmax), N)
637+
y = np.geomspace(vmin, vmax, N)
638638
else:
639639
y = np.linspace(vmin, vmax, N)
640640
return y

tutorials/introductory/usage.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ def my_plotter(ax, data1, data2, param_dict):
670670
# # Setup, and create the data to plot
671671
# y = np.random.rand(100000)
672672
# y[50000:] *= 2
673-
# y[np.logspace(1, np.log10(50000), 400).astype(int)] = -1
673+
# y[np.geomspace(10, 50000, 400).astype(int)] = -1
674674
# mpl.rcParams['path.simplify'] = True
675675
#
676676
# mpl.rcParams['path.simplify_threshold'] = 0.0
@@ -749,7 +749,7 @@ def my_plotter(ax, data1, data2, param_dict):
749749
# # Setup, and create the data to plot
750750
# y = np.random.rand(100000)
751751
# y[50000:] *= 2
752-
# y[np.logspace(1, np.log10(50000), 400).astype(int)] = -1
752+
# y[np.geomspace(10, 50000, 400).astype(int)] = -1
753753
# mpl.rcParams['path.simplify'] = True
754754
#
755755
# mpl.rcParams['agg.path.chunksize'] = 0

0 commit comments

Comments
 (0)