5
5
class. Originally, this change was motivated to support curvilinear
6
6
grid. Here are a few reasons that I came up with a new axes class:
7
7
8
+ * "top" and "bottom" x-axis (or "left" and "right" y-axis) can have
9
+ different ticks (tick locations and labels). This is not possible
10
+ with the current mpl, although some twin axes trick can help.
8
11
9
- * "top" and "bottom" x-axis (or "left" and "right" y-axis) can have
10
- different ticks (tick locations and labels). This is not possible
11
- with the current mpl, although some twin axes trick can help.
12
+ * Curvilinear grid.
12
13
13
- * Curvilinear grid.
14
-
15
- * angled ticks.
14
+ * angled ticks.
16
15
17
16
In the new axes class, xaxis and yaxis is set to not visible by
18
17
default, and new set of artist (AxisArtist) are defined to draw axis
24
23
AxisArtist can be considered as a container artist and
25
24
has following children artists which will draw ticks, labels, etc.
26
25
27
- * line
28
- * major_ticks, major_ticklabels
29
- * minor_ticks, minor_ticklabels
30
- * offsetText
31
- * label
26
+ * line
27
+ * major_ticks, major_ticklabels
28
+ * minor_ticks, minor_ticklabels
29
+ * offsetText
30
+ * label
32
31
33
32
Note that these are separate artists from Axis class of the
34
33
original mpl, thus most of tick-related command in the original mpl
@@ -198,7 +197,8 @@ def get_nth_coord(self):
198
197
return self .nth_coord
199
198
200
199
def get_line (self , axes ):
201
- raise RuntimeError ("get_line method should be defined by the derived class" )
200
+ raise RuntimeError (
201
+ "get_line method should be defined by the derived class" )
202
202
203
203
204
204
class AxisArtistHelperRectlinear (object ):
@@ -228,12 +228,14 @@ def get_tick_iterators(self, axes):
228
228
major = self .axis .major
229
229
majorLocs = major .locator ()
230
230
major .formatter .set_locs (majorLocs )
231
- majorLabels = [major .formatter (val , i ) for i , val in enumerate (majorLocs )]
231
+ majorLabels = [major .formatter (val , i )
232
+ for i , val in enumerate (majorLocs )]
232
233
233
234
minor = self .axis .minor
234
235
minorLocs = minor .locator ()
235
236
minor .formatter .set_locs (minorLocs )
236
- minorLabels = [minor .formatter (val , i ) for i , val in enumerate (minorLocs )]
237
+ minorLabels = [minor .formatter (val , i )
238
+ for i , val in enumerate (minorLocs )]
237
239
238
240
trans_tick = self .get_tick_transform (axes )
239
241
@@ -247,7 +249,9 @@ def _f(locs, labels):
247
249
248
250
# check if the tick point is inside axes
249
251
c2 = tr2ax .transform_point (c )
250
- if 0 - self .delta1 <= c2 [self .nth_coord ] <= 1 + self .delta2 :
252
+ if (0 - self .delta1
253
+ <= c2 [self .nth_coord ]
254
+ <= 1 + self .delta2 ):
251
255
yield c , angle_normal , angle_tangent , l
252
256
253
257
return _f (majorLocs , majorLabels ), _f (minorLocs , minorLabels )
@@ -263,10 +267,9 @@ def get_line(self, axes):
263
267
_verts = np .array ([[0. , 0. ],
264
268
[1. , 1. ]])
265
269
266
- fixed_coord = 1 - self .nth_coord
267
- trans_passingthrough_point = axes .transData + axes .transAxes .inverted ()
268
- p = trans_passingthrough_point .transform_point ([self ._value ,
269
- self ._value ])
270
+ fixed_coord = 1 - self .nth_coord
271
+ p = (axes .transData + axes .transAxes .inverted ()).transform_point (
272
+ [self ._value , self ._value ])
270
273
_verts [:, fixed_coord ] = p [fixed_coord ]
271
274
272
275
return Path (_verts )
@@ -297,9 +300,8 @@ def get_axislabel_pos_angle(self, axes):
297
300
_verts = [0.5 , 0.5 ]
298
301
299
302
fixed_coord = 1 - self .nth_coord
300
- trans_passingthrough_point = axes .transData + axes .transAxes .inverted ()
301
- p = trans_passingthrough_point .transform_point ([self ._value ,
302
- self ._value ])
303
+ p = (axes .transData + axes .transAxes .inverted ()).transform_point (
304
+ [self ._value , self ._value ])
303
305
_verts [fixed_coord ] = p [fixed_coord ]
304
306
if not (0. <= _verts [fixed_coord ] <= 1. ):
305
307
return None , None
@@ -329,12 +331,14 @@ def get_tick_iterators(self, axes):
329
331
major = self .axis .major
330
332
majorLocs = major .locator ()
331
333
major .formatter .set_locs (majorLocs )
332
- majorLabels = [major .formatter (val , i ) for i , val in enumerate (majorLocs )]
334
+ majorLabels = [major .formatter (val , i )
335
+ for i , val in enumerate (majorLocs )]
333
336
334
337
minor = self .axis .minor
335
338
minorLocs = minor .locator ()
336
339
minor .formatter .set_locs (minorLocs )
337
- minorLabels = [minor .formatter (val , i ) for i , val in enumerate (minorLocs )]
340
+ minorLabels = [minor .formatter (val , i )
341
+ for i , val in enumerate (minorLocs )]
338
342
339
343
tr2ax = axes .transData + axes .transAxes .inverted ()
340
344
@@ -424,7 +428,8 @@ def new_fixed_axis(self, loc,
424
428
):
425
429
426
430
if axes is None :
427
- warnings .warn ("'new_fixed_axis' explicitly requires the axes keyword." )
431
+ warnings .warn (
432
+ "'new_fixed_axis' explicitly requires the axes keyword." )
428
433
axes = self .axes
429
434
430
435
_helper = AxisArtistHelperRectlinear .Fixed (axes , loc , nth_coord )
@@ -615,12 +620,10 @@ def grid(self, b=None, which='major', axis="both", **kwargs):
615
620
return
616
621
617
622
if b is None :
618
-
619
- if self .axes .xaxis ._gridOnMinor or self .axes .xaxis ._gridOnMajor or \
620
- self .axes .yaxis ._gridOnMinor or self .axes .yaxis ._gridOnMajor :
621
- b = True
622
- else :
623
- b = False
623
+ b = (self .axes .xaxis ._gridOnMinor
624
+ or self .axes .xaxis ._gridOnMajor
625
+ or self .axes .yaxis ._gridOnMinor
626
+ or self .axes .yaxis ._gridOnMajor )
624
627
625
628
self .gridlines .set_which (which )
626
629
self .gridlines .set_axis (axis )
0 commit comments