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

Skip to content

Commit 1d22b90

Browse files
alvarosgalvarosg
alvarosg
authored andcommitted
Major update: complete refactorization of code. A much more powerful version of ArbitraryNorm introduced. All the other classes now derive from this one. Included support for certain named functions as strings. Added automatic normalization of the provided functions. A smarter automatic way of adding ticks to the colorbar implemented. Examples changed accordingly.
1 parent ffe1b9d commit 1d22b90

File tree

3 files changed

+262
-271
lines changed

3 files changed

+262
-271
lines changed

doc/users/plotting/examples/colormap_normalizations_arbitrarynorm.py

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,8 @@ def gauss2d(x, y, a0, x0, y0, wx, wy):
4545

4646
cmap = cm.gist_rainbow
4747

48-
norms = [('Linear Scale', None),
49-
('Arbitrary norm',
50-
colors.ArbitraryNorm(fpos=(lambda x: x**0.2),
51-
fposinv=(lambda x: x**5),
52-
fneg=(lambda x: x**0.5),
53-
fneginv=(lambda x: x**2),
54-
center=0.4)),
55-
('Positive arbitrary norm',
56-
colors.PositiveArbitraryNorm(vmin=0,
57-
fpos=(lambda x: x**0.5),
58-
fposinv=(lambda x: x**2))),
59-
('Negative arbitrary norm',
60-
colors.NegativeArbitraryNorm(vmax=0,
61-
fneg=(lambda x: x**0.5),
62-
fneginv=(lambda x: x**2)))]
63-
64-
65-
for label, norm in norms:
48+
49+
def makePlot(norm, label):
6650
fig, ax = plt.subplots()
6751
cax = ax.pcolormesh(x, y, data, cmap=cmap, norm=norm)
6852
ax.set_title(label)
@@ -74,4 +58,29 @@ def gauss2d(x, y, a0, x0, y0, wx, wy):
7458
ticks = None
7559
cbar = fig.colorbar(cax, format='%.3g', ticks=ticks)
7660

61+
62+
makePlot(None, 'Regular linear scale')
63+
64+
65+
norm = colors.SingleArbitraryNorm(vmin=0, f='sqrt')
66+
makePlot(norm, 'Single arbitrary norm')
67+
68+
norm = colors.SingleArbitraryNorm(vmin=0,
69+
f=(lambda x: x**0.25),
70+
finv=(lambda x: x**4))
71+
makePlot(norm, 'Simple arbitrary norm, custom function')
72+
73+
74+
norm = colors.MirrorArbitraryNorm(fpos='crt',
75+
fneg='linear',
76+
center_cm=0.3,
77+
center_data=0.0)
78+
makePlot(norm, 'Mirror arbitrary norm')
79+
80+
81+
norm = colors.ArbitraryNorm(flist=['linear', 'quadratic', 'cubic'],
82+
refpoints_cm=[0.5, 0.75],
83+
refpoints_data=[0., 1.])
84+
makePlot(norm, 'Arbitrary norm')
85+
7786
plt.show()

doc/users/plotting/examples/colormap_normalizations_rootnorm.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Examples of colormap root normalization
44
============================================
55
6-
Here I plot an image array with data spanning for a large dynamic range,
6+
Here I plot an image array with data spanning for a large dynamic range,
77
using different normalizations. Look at how each of them enhances
88
different features.
99
@@ -44,16 +44,8 @@ def gauss2d(x, y, a0, x0, y0, wx, wy):
4444

4545
cmap = cm.gist_rainbow
4646

47-
norms = [('Linear Scale', None),
48-
('Symmetric root norm',
49-
colors.SymRootNorm(orderpos=7, orderneg=2, center=0.3)),
50-
('Positive root norm',
51-
colors.PositiveRootNorm(vmin=0, orderpos=5)),
52-
('Negative root norm',
53-
colors.NegativeRootNorm(vmax=0, orderneg=5))]
5447

55-
56-
for label, norm in norms:
48+
def makePlot(norm, label):
5749
fig, ax = plt.subplots()
5850
cax = ax.pcolormesh(x, y, data, cmap=cmap, norm=norm)
5951
ax.set_title(label)
@@ -65,4 +57,14 @@ def gauss2d(x, y, a0, x0, y0, wx, wy):
6557
ticks = None
6658
cbar = fig.colorbar(cax, format='%.3g', ticks=ticks)
6759

60+
61+
makePlot(None, 'Regular linear scale')
62+
63+
norm = colors.RootNorm(vmin=0, orderpos=5)
64+
makePlot(norm, 'Root norm')
65+
66+
norm = colors.MirrorRootNorm(
67+
orderpos=7, orderneg=2, center_cm=0.3, center_data=0.)
68+
makePlot(norm, 'Mirror root norm')
69+
6870
plt.show()

0 commit comments

Comments
 (0)