1
1
"""
2
2
Classes for the ticks and x and y axis
3
3
"""
4
- from __future__ import (absolute_import , division , print_function ,
5
- unicode_literals )
6
-
7
- import six
8
4
5
+ import datetime
9
6
import logging
7
+ import warnings
8
+
9
+ import numpy as np
10
10
11
11
from matplotlib import rcParams
12
12
import matplotlib .artist as artist
21
21
import matplotlib .ticker as mticker
22
22
import matplotlib .transforms as mtransforms
23
23
import matplotlib .units as munits
24
- import numpy as np
25
- import warnings
26
24
27
25
_log = logging .getLogger (__name__ )
28
26
@@ -190,7 +188,7 @@ def __init__(self, axes, loc, label,
190
188
self .update_position (loc )
191
189
192
190
def _set_labelrotation (self , labelrotation ):
193
- if isinstance (labelrotation , six . string_types ):
191
+ if isinstance (labelrotation , str ):
194
192
mode = labelrotation
195
193
angle = 0
196
194
elif isinstance (labelrotation , (tuple , list )):
@@ -236,7 +234,7 @@ def set_clip_path(self, clippath, transform=None):
236
234
set_clip_path .__doc__ = artist .Artist .set_clip_path .__doc__
237
235
238
236
def get_pad_pixels (self ):
239
- return self .figure .dpi * self ._base_pad / 72.0
237
+ return self .figure .dpi * self ._base_pad / 72
240
238
241
239
def contains (self , mouseevent ):
242
240
"""
@@ -360,39 +358,33 @@ def _apply_params(self, **kw):
360
358
self .label1 .set_transform (trans )
361
359
trans = self ._get_text2_transform ()[0 ]
362
360
self .label2 .set_transform (trans )
363
- tick_kw = {k : v for k , v in six .iteritems (kw )
364
- if k in ['color' , 'zorder' ]}
365
- if tick_kw :
366
- self .tick1line .set (** tick_kw )
367
- self .tick2line .set (** tick_kw )
368
- for k , v in six .iteritems (tick_kw ):
369
- setattr (self , '_' + k , v )
361
+ tick_kw = {k : v for k , v in kw .items () if k in ['color' , 'zorder' ]}
362
+ self .tick1line .set (** tick_kw )
363
+ self .tick2line .set (** tick_kw )
364
+ for k , v in tick_kw .items ():
365
+ setattr (self , '_' + k , v )
370
366
371
367
if 'labelrotation' in kw :
372
368
self ._set_labelrotation (kw .pop ('labelrotation' ))
373
369
self .label1 .set (rotation = self ._labelrotation [1 ])
374
370
self .label2 .set (rotation = self ._labelrotation [1 ])
375
371
376
- label_list = [k for k in six .iteritems (kw )
377
- if k [0 ] in ['labelsize' , 'labelcolor' ]]
378
- if label_list :
379
- label_kw = {k [5 :]: v for k , v in label_list }
380
- self .label1 .set (** label_kw )
381
- self .label2 .set (** label_kw )
382
- for k , v in six .iteritems (label_kw ):
383
- # for labelsize the text objects covert str ('small')
384
- # -> points. grab the integer from the `Text` object
385
- # instead of saving the string representation
386
- v = getattr (self .label1 , 'get_' + k )()
387
- setattr (self , '_label' + k , v )
388
-
389
- grid_list = [k for k in six .iteritems (kw )
390
- if k [0 ] in _gridline_param_names ]
391
- if grid_list :
392
- grid_kw = {k [5 :]: v for k , v in grid_list }
393
- self .gridline .set (** grid_kw )
394
- for k , v in six .iteritems (grid_kw ):
395
- setattr (self , '_grid_' + k , v )
372
+ label_kw = {k [5 :]: v for k , v in kw .items ()
373
+ if k in ['labelsize' , 'labelcolor' ]}
374
+ self .label1 .set (** label_kw )
375
+ self .label2 .set (** label_kw )
376
+ for k , v in label_kw .items ():
377
+ # for labelsize the text objects covert str ('small')
378
+ # -> points. grab the integer from the `Text` object
379
+ # instead of saving the string representation
380
+ v = getattr (self .label1 , 'get_' + k )()
381
+ setattr (self , '_label' + k , v )
382
+
383
+ grid_kw = {k [5 :]: v for k , v in kw .items ()
384
+ if k in _gridline_param_names }
385
+ self .gridline .set (** grid_kw )
386
+ for k , v in grid_kw .items ():
387
+ setattr (self , '_grid_' + k , v )
396
388
397
389
def update_position (self , loc ):
398
390
'Set the location of tick in data coords with scalar *loc*'
@@ -1174,9 +1166,7 @@ def get_tick_padding(self):
1174
1166
values .append (self .majorTicks [0 ].get_tick_padding ())
1175
1167
if len (self .minorTicks ):
1176
1168
values .append (self .minorTicks [0 ].get_tick_padding ())
1177
- if len (values ):
1178
- return max (values )
1179
- return 0.0
1169
+ return max (values , default = 0 )
1180
1170
1181
1171
@allow_rasterization
1182
1172
def draw (self , renderer , * args , ** kwargs ):
@@ -1737,12 +1727,10 @@ def axis_date(self, tz=None):
1737
1727
*tz* is a :class:`tzinfo` instance or a timezone string.
1738
1728
This timezone is used to create date labels.
1739
1729
"""
1740
- # By providing a sample datetime instance with the desired
1741
- # timezone, the registered converter can be selected,
1742
- # and the "units" attribute, which is the timezone, can
1743
- # be set.
1744
- import datetime
1745
- if isinstance (tz , six .string_types ):
1730
+ # By providing a sample datetime instance with the desired timezone,
1731
+ # the registered converter can be selected, and the "units" attribute,
1732
+ # which is the timezone, can be set.
1733
+ if isinstance (tz , str ):
1746
1734
import pytz
1747
1735
tz = pytz .timezone (tz )
1748
1736
self .update_units (datetime .datetime (2009 , 1 , 1 , 0 , 0 , 0 , 0 , tz ))
@@ -1790,9 +1778,9 @@ def contains(self, mouseevent):
1790
1778
return False , {}
1791
1779
l , b = self .axes .transAxes .transform_point ((0 , 0 ))
1792
1780
r , t = self .axes .transAxes .transform_point ((1 , 1 ))
1793
- inaxis = xaxes >= 0 and xaxes <= 1 and (
1794
- ( y < b and y > b - self . pickradius ) or
1795
- ( y > t and y < t + self .pickradius ) )
1781
+ inaxis = 0 <= xaxes <= 1 and (
1782
+ b - self . pickradius < y < b or
1783
+ t < y < t + self .pickradius )
1796
1784
return inaxis , {}
1797
1785
1798
1786
def _get_tick (self , major ):
@@ -1929,7 +1917,7 @@ def _update_label_position(self, renderer):
1929
1917
bottom = bbox .y0
1930
1918
1931
1919
self .label .set_position (
1932
- (x , bottom - self .labelpad * self .figure .dpi / 72.0 )
1920
+ (x , bottom - self .labelpad * self .figure .dpi / 72 )
1933
1921
)
1934
1922
1935
1923
else :
@@ -1944,7 +1932,7 @@ def _update_label_position(self, renderer):
1944
1932
top = bbox .y1
1945
1933
1946
1934
self .label .set_position (
1947
- (x , top + self .labelpad * self .figure .dpi / 72.0 )
1935
+ (x , top + self .labelpad * self .figure .dpi / 72 )
1948
1936
)
1949
1937
1950
1938
def _update_offset_text_position (self , bboxes , bboxes2 ):
@@ -1959,7 +1947,7 @@ def _update_offset_text_position(self, bboxes, bboxes2):
1959
1947
bbox = mtransforms .Bbox .union (bboxes )
1960
1948
bottom = bbox .y0
1961
1949
self .offsetText .set_position (
1962
- (x , bottom - self .OFFSETTEXTPAD * self .figure .dpi / 72.0 )
1950
+ (x , bottom - self .OFFSETTEXTPAD * self .figure .dpi / 72 )
1963
1951
)
1964
1952
1965
1953
def get_text_heights (self , renderer ):
@@ -2131,7 +2119,7 @@ def set_default_intervals(self):
2131
2119
2132
2120
def get_tick_space (self ):
2133
2121
ends = self .axes .transAxes .transform ([[0 , 0 ], [1 , 0 ]])
2134
- length = ((ends [1 ][0 ] - ends [0 ][0 ]) / self .axes .figure .dpi ) * 72.0
2122
+ length = ((ends [1 ][0 ] - ends [0 ][0 ]) / self .axes .figure .dpi ) * 72
2135
2123
tick = self ._get_tick (True )
2136
2124
# There is a heuristic here that the aspect ratio of tick text
2137
2125
# is no more than 3:1
@@ -2162,9 +2150,9 @@ def contains(self, mouseevent):
2162
2150
return False , {}
2163
2151
l , b = self .axes .transAxes .transform_point ((0 , 0 ))
2164
2152
r , t = self .axes .transAxes .transform_point ((1 , 1 ))
2165
- inaxis = yaxes >= 0 and yaxes <= 1 and (
2166
- ( x < l and x > l - self . pickradius ) or
2167
- ( x > r and x < r + self .pickradius ) )
2153
+ inaxis = 0 <= yaxes <= 1 and (
2154
+ l - self . pickradius < x < l or
2155
+ r < x < r + self .pickradius )
2168
2156
return inaxis , {}
2169
2157
2170
2158
def _get_tick (self , major ):
@@ -2297,7 +2285,7 @@ def _update_label_position(self, renderer):
2297
2285
bbox = mtransforms .Bbox .union (bboxes + [spinebbox ])
2298
2286
left = bbox .x0
2299
2287
self .label .set_position (
2300
- (left - self .labelpad * self .figure .dpi / 72.0 , y )
2288
+ (left - self .labelpad * self .figure .dpi / 72 , y )
2301
2289
)
2302
2290
2303
2291
else :
@@ -2312,7 +2300,7 @@ def _update_label_position(self, renderer):
2312
2300
right = bbox .x1
2313
2301
2314
2302
self .label .set_position (
2315
- (right + self .labelpad * self .figure .dpi / 72.0 , y )
2303
+ (right + self .labelpad * self .figure .dpi / 72 , y )
2316
2304
)
2317
2305
2318
2306
def _update_offset_text_position (self , bboxes , bboxes2 ):
@@ -2323,7 +2311,7 @@ def _update_offset_text_position(self, bboxes, bboxes2):
2323
2311
x , y = self .offsetText .get_position ()
2324
2312
top = self .axes .bbox .ymax
2325
2313
self .offsetText .set_position (
2326
- (x , top + self .OFFSETTEXTPAD * self .figure .dpi / 72.0 )
2314
+ (x , top + self .OFFSETTEXTPAD * self .figure .dpi / 72 )
2327
2315
)
2328
2316
2329
2317
def set_offset_position (self , position ):
@@ -2510,7 +2498,7 @@ def set_default_intervals(self):
2510
2498
2511
2499
def get_tick_space (self ):
2512
2500
ends = self .axes .transAxes .transform ([[0 , 0 ], [0 , 1 ]])
2513
- length = ((ends [1 ][1 ] - ends [0 ][1 ]) / self .axes .figure .dpi ) * 72.0
2501
+ length = ((ends [1 ][1 ] - ends [0 ][1 ]) / self .axes .figure .dpi ) * 72
2514
2502
tick = self ._get_tick (True )
2515
2503
# Having a spacing of at least 2 just looks good.
2516
2504
size = tick .label1 .get_size () * 2.0
0 commit comments