@@ -109,36 +109,26 @@ def get_tick_iterators(self, axes):
109
109
"""
110
110
111
111
class _Base (object ):
112
- """
113
- Base class for axis helper.
114
- """
112
+ """Base class for axis helper."""
115
113
def __init__ (self ):
116
- """
117
- """
118
114
self .delta1 , self .delta2 = 0.00001 , 0.00001
119
115
120
116
def update_lim (self , axes ):
121
117
pass
122
118
123
-
124
119
class Fixed (_Base ):
125
- """
126
- Helper class for a fixed (in the axes coordinate) axis.
127
- """
120
+ """Helper class for a fixed (in the axes coordinate) axis."""
128
121
129
122
_default_passthru_pt = dict (left = (0 , 0 ),
130
123
right = (1 , 0 ),
131
124
bottom = (0 , 0 ),
132
125
top = (0 , 1 ))
133
126
134
- def __init__ (self ,
135
- loc , nth_coord = None ,
136
- ):
127
+ def __init__ (self , loc , nth_coord = None ):
137
128
"""
138
129
nth_coord = along which coordinate value varies
139
130
in 2d, nth_coord = 0 -> x axis, nth_coord = 1 -> y axis
140
131
"""
141
-
142
132
self ._loc = loc
143
133
144
134
if loc not in ["left" , "right" , "bottom" , "top" ]:
@@ -156,8 +146,6 @@ def __init__(self,
156
146
157
147
self .passthru_pt = self ._default_passthru_pt [loc ]
158
148
159
-
160
-
161
149
_verts = np .array ([[0. , 0. ],
162
150
[1. , 1. ]])
163
151
fixed_coord = 1 - nth_coord
@@ -166,7 +154,6 @@ def __init__(self,
166
154
# axis line in transAxes
167
155
self ._path = Path (_verts )
168
156
169
-
170
157
def get_nth_coord (self ):
171
158
return self .nth_coord
172
159
@@ -197,8 +184,6 @@ def get_axislabel_pos_angle(self, axes):
197
184
198
185
return pos , angle_tangent
199
186
200
-
201
-
202
187
# TICK
203
188
204
189
def get_tick_transform (self , axes ):
@@ -221,8 +206,6 @@ def get_line(self, axes):
221
206
raise RuntimeError ("get_line method should be defined by the derived class" )
222
207
223
208
224
-
225
-
226
209
class AxisArtistHelperRectlinear (object ):
227
210
228
211
class Fixed (AxisArtistHelper .Fixed ):
@@ -275,8 +258,6 @@ def _f(locs, labels):
275
258
276
259
return _f (majorLocs , majorLabels ), _f (minorLocs , minorLabels )
277
260
278
-
279
-
280
261
class Floating (AxisArtistHelper .Floating ):
281
262
def __init__ (self , axes , nth_coord ,
282
263
passingthrough_point , axis_direction = "bottom" ):
@@ -331,12 +312,9 @@ def get_axislabel_pos_angle(self, axes):
331
312
else :
332
313
return _verts , angle
333
314
334
-
335
-
336
315
def get_tick_transform (self , axes ):
337
316
return axes .transData
338
317
339
-
340
318
def get_tick_iterators (self , axes ):
341
319
"""tick_loc, tick_angle, tick_label"""
342
320
@@ -352,7 +330,7 @@ def get_tick_iterators(self, axes):
352
330
else :
353
331
angle_normal , angle_tangent = 0 , 90
354
332
355
- #angle = 90 - 90 * self.nth_coord
333
+ # angle = 90 - 90 * self.nth_coord
356
334
357
335
major = self .axis .major
358
336
majorLocs = major .locator ()
@@ -381,17 +359,13 @@ def _f(locs, labels):
381
359
return _f (majorLocs , majorLabels ), _f (minorLocs , minorLabels )
382
360
383
361
384
-
385
-
386
-
387
362
class GridHelperBase (object ):
388
363
389
364
def __init__ (self ):
390
365
self ._force_update = True
391
366
self ._old_limits = None
392
367
super ().__init__ ()
393
368
394
-
395
369
def update_lim (self , axes ):
396
370
x1 , x2 = axes .get_xlim ()
397
371
y1 , y2 = axes .get_ylim ()
@@ -401,18 +375,15 @@ def update_lim(self, axes):
401
375
self ._force_update = False
402
376
self ._old_limits = (x1 , x2 , y1 , y2 )
403
377
404
-
405
378
def _update (self , x1 , x2 , y1 , y2 ):
406
379
pass
407
380
408
-
409
381
def invalidate (self ):
410
382
self ._force_update = True
411
383
412
384
def valid (self ):
413
385
return not self ._force_update
414
386
415
-
416
387
def get_gridlines (self , which , axis ):
417
388
"""
418
389
Return list of grid lines as a list of paths (list of points).
@@ -447,14 +418,10 @@ def new_gridlines(self, ax):
447
418
448
419
class GridHelperRectlinear (GridHelperBase ):
449
420
450
-
451
421
def __init__ (self , axes ):
452
-
453
422
super ().__init__ ()
454
423
self .axes = axes
455
424
456
-
457
-
458
425
def new_fixed_axis (self , loc ,
459
426
nth_coord = None ,
460
427
axis_direction = None ,
@@ -476,7 +443,6 @@ def new_fixed_axis(self, loc,
476
443
477
444
return axisline
478
445
479
-
480
446
def new_floating_axis (self , nth_coord , value ,
481
447
axis_direction = "bottom" ,
482
448
axes = None ,
@@ -499,40 +465,32 @@ def new_floating_axis(self, nth_coord, value,
499
465
axisline .line .set_clip_box (axisline .axes .bbox )
500
466
return axisline
501
467
502
-
503
468
def get_gridlines (self , which = "major" , axis = "both" ):
504
469
"""
505
470
return list of gridline coordinates in data coordinates.
506
471
507
472
*which* : "major" or "minor"
508
473
*axis* : "both", "x" or "y"
509
474
"""
510
-
511
475
gridlines = []
512
476
513
-
514
477
if axis in ["both" , "x" ]:
515
478
locs = []
516
479
y1 , y2 = self .axes .get_ylim ()
517
- #if self.axes.xaxis._gridOnMajor:
518
480
if which in ["both" , "major" ]:
519
481
locs .extend (self .axes .xaxis .major .locator ())
520
- #if self.axes.xaxis._gridOnMinor:
521
482
if which in ["both" , "minor" ]:
522
483
locs .extend (self .axes .xaxis .minor .locator ())
523
484
524
485
for x in locs :
525
486
gridlines .append ([[x , x ], [y1 , y2 ]])
526
487
527
-
528
488
if axis in ["both" , "y" ]:
529
489
x1 , x2 = self .axes .get_xlim ()
530
490
locs = []
531
491
if self .axes .yaxis ._gridOnMajor :
532
- #if which in ["both", "major"]:
533
492
locs .extend (self .axes .yaxis .major .locator ())
534
493
if self .axes .yaxis ._gridOnMinor :
535
- #if which in ["both", "minor"]:
536
494
locs .extend (self .axes .yaxis .minor .locator ())
537
495
538
496
for y in locs :
@@ -541,10 +499,6 @@ def get_gridlines(self, which="major", axis="both"):
541
499
return gridlines
542
500
543
501
544
-
545
-
546
-
547
-
548
502
class SimpleChainedObjects (object ):
549
503
def __init__ (self , objects ):
550
504
self ._objects = objects
@@ -581,24 +535,13 @@ def __getitem__(self, k):
581
535
def __call__ (self , * v , ** kwargs ):
582
536
return maxes .Axes .axis (self .axes , * v , ** kwargs )
583
537
584
-
585
- def __init__ (self , * kl , ** kw ):
586
-
587
-
588
- helper = kw .pop ("grid_helper" , None )
589
-
538
+ def __init__ (self , * args , grid_helper = None , ** kwargs ):
590
539
self ._axisline_on = True
591
-
592
- if helper :
593
- self ._grid_helper = helper
594
- else :
595
- self ._grid_helper = GridHelperRectlinear (self )
596
-
597
- super ().__init__ (* kl , ** kw )
598
-
540
+ self ._grid_helper = (grid_helper if grid_helper
541
+ else GridHelperRectlinear (self ))
542
+ super ().__init__ (* args , ** kwargs )
599
543
self .toggle_axisline (True )
600
544
601
-
602
545
def toggle_axisline (self , b = None ):
603
546
if b is None :
604
547
b = not self ._axisline_on
@@ -615,11 +558,9 @@ def toggle_axisline(self, b=None):
615
558
self .xaxis .set_visible (True )
616
559
self .yaxis .set_visible (True )
617
560
618
-
619
561
def _init_axis (self ):
620
562
super ()._init_axis ()
621
563
622
-
623
564
def _init_axis_artists (self , axes = None ):
624
565
if axes is None :
625
566
axes = self
@@ -651,19 +592,14 @@ def new_gridlines(self, grid_helper=None):
651
592
grid_helper = self .get_grid_helper ()
652
593
653
594
gridlines = grid_helper .new_gridlines (self )
654
-
655
595
return gridlines
656
596
657
-
658
597
def _init_gridlines (self , grid_helper = None ):
659
598
# It is done inside the cla.
660
- gridlines = self .new_gridlines (grid_helper )
661
-
662
- self .gridlines = gridlines
599
+ self .gridlines = self .new_gridlines (grid_helper )
663
600
664
601
def cla (self ):
665
602
# gridlines need to b created before cla() since cla calls grid()
666
-
667
603
self ._init_gridlines ()
668
604
super ().cla ()
669
605
@@ -676,7 +612,6 @@ def cla(self):
676
612
def get_grid_helper (self ):
677
613
return self ._grid_helper
678
614
679
-
680
615
def grid (self , b = None , which = 'major' , axis = "both" , ** kwargs ):
681
616
"""
682
617
Toggle the gridlines, and optionally set the properties of the lines.
@@ -715,7 +650,6 @@ def get_children(self):
715
650
def invalidate_grid_helper (self ):
716
651
self ._grid_helper .invalidate ()
717
652
718
-
719
653
def new_fixed_axis (self , loc , offset = None ):
720
654
gh = self .get_grid_helper ()
721
655
axis = gh .new_fixed_axis (loc ,
@@ -727,9 +661,7 @@ def new_fixed_axis(self, loc, offset=None):
727
661
return axis
728
662
729
663
730
- def new_floating_axis (self , nth_coord , value ,
731
- axis_direction = "bottom" ,
732
- ):
664
+ def new_floating_axis (self , nth_coord , value , axis_direction = "bottom" ):
733
665
gh = self .get_grid_helper ()
734
666
axis = gh .new_floating_axis (nth_coord , value ,
735
667
axis_direction = axis_direction ,
0 commit comments