11"""
22Classes for the ticks and x and y axis
33"""
4- from __future__ import (absolute_import , division , print_function ,
5- unicode_literals )
6-
7- import six
84
5+ import datetime
96import logging
7+ import warnings
8+
9+ import numpy as np
1010
1111from matplotlib import rcParams
1212import matplotlib .artist as artist
2121import matplotlib .ticker as mticker
2222import matplotlib .transforms as mtransforms
2323import matplotlib .units as munits
24- import numpy as np
25- import warnings
2624
2725_log = logging .getLogger (__name__ )
2826
@@ -190,7 +188,7 @@ def __init__(self, axes, loc, label,
190188 self .update_position (loc )
191189
192190 def _set_labelrotation (self , labelrotation ):
193- if isinstance (labelrotation , six . string_types ):
191+ if isinstance (labelrotation , str ):
194192 mode = labelrotation
195193 angle = 0
196194 elif isinstance (labelrotation , (tuple , list )):
@@ -236,7 +234,7 @@ def set_clip_path(self, clippath, transform=None):
236234 set_clip_path .__doc__ = artist .Artist .set_clip_path .__doc__
237235
238236 def get_pad_pixels (self ):
239- return self .figure .dpi * self ._base_pad / 72.0
237+ return self .figure .dpi * self ._base_pad / 72
240238
241239 def contains (self , mouseevent ):
242240 """
@@ -360,39 +358,33 @@ def _apply_params(self, **kw):
360358 self .label1 .set_transform (trans )
361359 trans = self ._get_text2_transform ()[0 ]
362360 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 )
370366
371367 if 'labelrotation' in kw :
372368 self ._set_labelrotation (kw .pop ('labelrotation' ))
373369 self .label1 .set (rotation = self ._labelrotation [1 ])
374370 self .label2 .set (rotation = self ._labelrotation [1 ])
375371
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 )
396388
397389 def update_position (self , loc ):
398390 'Set the location of tick in data coords with scalar *loc*'
@@ -1174,9 +1166,7 @@ def get_tick_padding(self):
11741166 values .append (self .majorTicks [0 ].get_tick_padding ())
11751167 if len (self .minorTicks ):
11761168 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 )
11801170
11811171 @allow_rasterization
11821172 def draw (self , renderer , * args , ** kwargs ):
@@ -1737,12 +1727,10 @@ def axis_date(self, tz=None):
17371727 *tz* is a :class:`tzinfo` instance or a timezone string.
17381728 This timezone is used to create date labels.
17391729 """
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 ):
17461734 import pytz
17471735 tz = pytz .timezone (tz )
17481736 self .update_units (datetime .datetime (2009 , 1 , 1 , 0 , 0 , 0 , 0 , tz ))
@@ -1790,9 +1778,9 @@ def contains(self, mouseevent):
17901778 return False , {}
17911779 l , b = self .axes .transAxes .transform_point ((0 , 0 ))
17921780 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 )
17961784 return inaxis , {}
17971785
17981786 def _get_tick (self , major ):
@@ -1929,7 +1917,7 @@ def _update_label_position(self, renderer):
19291917 bottom = bbox .y0
19301918
19311919 self .label .set_position (
1932- (x , bottom - self .labelpad * self .figure .dpi / 72.0 )
1920+ (x , bottom - self .labelpad * self .figure .dpi / 72 )
19331921 )
19341922
19351923 else :
@@ -1944,7 +1932,7 @@ def _update_label_position(self, renderer):
19441932 top = bbox .y1
19451933
19461934 self .label .set_position (
1947- (x , top + self .labelpad * self .figure .dpi / 72.0 )
1935+ (x , top + self .labelpad * self .figure .dpi / 72 )
19481936 )
19491937
19501938 def _update_offset_text_position (self , bboxes , bboxes2 ):
@@ -1959,7 +1947,7 @@ def _update_offset_text_position(self, bboxes, bboxes2):
19591947 bbox = mtransforms .Bbox .union (bboxes )
19601948 bottom = bbox .y0
19611949 self .offsetText .set_position (
1962- (x , bottom - self .OFFSETTEXTPAD * self .figure .dpi / 72.0 )
1950+ (x , bottom - self .OFFSETTEXTPAD * self .figure .dpi / 72 )
19631951 )
19641952
19651953 def get_text_heights (self , renderer ):
@@ -2131,7 +2119,7 @@ def set_default_intervals(self):
21312119
21322120 def get_tick_space (self ):
21332121 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
21352123 tick = self ._get_tick (True )
21362124 # There is a heuristic here that the aspect ratio of tick text
21372125 # is no more than 3:1
@@ -2162,9 +2150,9 @@ def contains(self, mouseevent):
21622150 return False , {}
21632151 l , b = self .axes .transAxes .transform_point ((0 , 0 ))
21642152 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 )
21682156 return inaxis , {}
21692157
21702158 def _get_tick (self , major ):
@@ -2297,7 +2285,7 @@ def _update_label_position(self, renderer):
22972285 bbox = mtransforms .Bbox .union (bboxes + [spinebbox ])
22982286 left = bbox .x0
22992287 self .label .set_position (
2300- (left - self .labelpad * self .figure .dpi / 72.0 , y )
2288+ (left - self .labelpad * self .figure .dpi / 72 , y )
23012289 )
23022290
23032291 else :
@@ -2312,7 +2300,7 @@ def _update_label_position(self, renderer):
23122300 right = bbox .x1
23132301
23142302 self .label .set_position (
2315- (right + self .labelpad * self .figure .dpi / 72.0 , y )
2303+ (right + self .labelpad * self .figure .dpi / 72 , y )
23162304 )
23172305
23182306 def _update_offset_text_position (self , bboxes , bboxes2 ):
@@ -2323,7 +2311,7 @@ def _update_offset_text_position(self, bboxes, bboxes2):
23232311 x , y = self .offsetText .get_position ()
23242312 top = self .axes .bbox .ymax
23252313 self .offsetText .set_position (
2326- (x , top + self .OFFSETTEXTPAD * self .figure .dpi / 72.0 )
2314+ (x , top + self .OFFSETTEXTPAD * self .figure .dpi / 72 )
23272315 )
23282316
23292317 def set_offset_position (self , position ):
@@ -2510,7 +2498,7 @@ def set_default_intervals(self):
25102498
25112499 def get_tick_space (self ):
25122500 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
25142502 tick = self ._get_tick (True )
25152503 # Having a spacing of at least 2 just looks good.
25162504 size = tick .label1 .get_size () * 2.0
0 commit comments