@@ -1043,7 +1043,13 @@ def _fun_normalizer(fun):
1043
1043
return (lambda x : (fun (x ) - fun (0. )) / (fun (1. ) - fun (0. )))
1044
1044
1045
1045
def ticks (self , N = 13 ):
1046
- return self .inverse (np .linspace (0 , 1 , N ))
1046
+ ticks = self .inverse (np .linspace (0 , 1 , N ))
1047
+ finalticks = np .zeros (ticks .shape , dtype = np .bool )
1048
+ finalticks [0 ] = True
1049
+ finalticks [0 ] = True
1050
+ ticks = FuncNorm ._round_ticks (ticks , finalticks )
1051
+
1052
+ return ticks
1047
1053
1048
1054
def autoscale (self , A ):
1049
1055
self .vmin = np .ma .min (A )
@@ -1057,6 +1063,19 @@ def autoscale_None(self, A):
1057
1063
if self .vmax is None :
1058
1064
self .vmax = np .ma .max (A )
1059
1065
1066
+ @staticmethod
1067
+ def _round_ticks (ticks , permanenttick ):
1068
+ ticks = ticks .copy ()
1069
+ for i in range (len (ticks )):
1070
+ if i == 0 or i == len (ticks ) - 1 or permanenttick [i ]:
1071
+ continue
1072
+ d1 = ticks [i ] - ticks [i - 1 ]
1073
+ d2 = ticks [i + 1 ] - ticks [i ]
1074
+ d = min ([d1 , d2 ])
1075
+ order = - np .floor (np .log10 (d ))
1076
+ ticks [i ] = float (np .round (ticks [i ] * 10 ** order )) / 10 ** order
1077
+ return ticks
1078
+
1060
1079
1061
1080
class PiecewiseNorm (FuncNorm ):
1062
1081
"""
@@ -1168,8 +1187,8 @@ def _build_f(self):
1168
1187
(x - rp_d [i ]) / widths_d [i ]) * widths_cm [i ] + rp_cm [i ])
1169
1188
masks .append (mask )
1170
1189
funcs .append (func )
1171
- maskmaker = (lambda x : [np .array ([mi (x ) == True ]) if np .isscalar (
1172
- x ) else mi (x ) == True for mi in masks ])
1190
+ maskmaker = (lambda x : [np .array ([mi (x )]) if np .isscalar (
1191
+ x ) else mi (x ) for mi in masks ])
1173
1192
f = (lambda x : np .piecewise (x , maskmaker (x ), funcs ))
1174
1193
return f
1175
1194
@@ -1195,8 +1214,8 @@ def _build_finv(self):
1195
1214
funcs .append (lambda x , i = i : self ._finvlist [i ](
1196
1215
(x - rp_cm [i ]) / widths_cm [i ]) * widths_d [i ] + rp_d [i ])
1197
1216
1198
- maskmaker = (lambda x : [np .array ([mi (x ) == True ]) if np .isscalar (
1199
- x ) else mi (x ) == True for mi in masks ])
1217
+ maskmaker = (lambda x : [np .array ([mi (x )]) if np .isscalar (
1218
+ x ) else mi (x ) for mi in masks ])
1200
1219
x = np .array ([0.5 , 1 ])
1201
1220
finv = (lambda x : np .piecewise (x , maskmaker (x ), funcs ))
1202
1221
return finv
@@ -1242,12 +1261,22 @@ def ticks(self, N=None):
1242
1261
N = nticks [i ]
1243
1262
auxticks = np .linspace (rp_cm [i ], rp_cm [i + 1 ], N + 2 )
1244
1263
ticks = np .concatenate ([ticks , auxticks [1 :- 1 ]])
1245
- return self .inverse (np .sort (ticks ))
1264
+
1265
+ finalticks = np .zeros (ticks .shape , dtype = np .bool )
1266
+ finalticks [0 :len (rp_cm )] = True
1267
+
1268
+ inds = np .argsort (ticks )
1269
+ ticks = ticks [inds ]
1270
+ finalticks = finalticks [inds ]
1271
+
1272
+ ticks = PiecewiseNorm ._round_ticks (self .inverse (ticks ), finalticks )
1273
+
1274
+ return ticks
1246
1275
1247
1276
1248
1277
class MirrorPiecewiseNorm (PiecewiseNorm ):
1249
1278
"""
1250
- Normalization allowing the definition of data ranges and colormap ranges,
1279
+ Normalization allowing the definition of data ranges and colormap ranges,
1251
1280
with a non linear map between each.
1252
1281
>>> norm=PiecewiseNorm(fpos=(lambda x: x**0.5),
1253
1282
>>> fposinv=(lambda x: x**2),
0 commit comments