@@ -1052,37 +1052,74 @@ class MaxNLocator(Locator):
10521052 """
10531053 Select no more than N intervals at nice locations.
10541054 """
1055-
1056- def __init__ (self , nbins = 10 , steps = None ,
1057- trim = True ,
1058- integer = False ,
1059- symmetric = False ,
1060- prune = None ):
1055+ default_params = dict (nbins = 10 ,
1056+ steps = None ,
1057+ trim = True ,
1058+ integer = False ,
1059+ symmetric = False ,
1060+ prune = None )
1061+ def __init__ (self , ** kwargs ):
10611062 """
10621063 Keyword args:
1064+
1065+ *nbins*
1066+ Maximum number of intervals; one less than max number of ticks.
1067+
1068+ *steps*
1069+ Sequence of nice numbers starting with 1 and ending with 10;
1070+ e.g., [1, 2, 4, 5, 10]
1071+
1072+ *integer*
1073+ If True, ticks will take only integer values.
1074+
1075+ *symmetric*
1076+ If True, autoscaling will result in a range symmetric
1077+ about zero.
1078+
10631079 *prune*
1080+ ['lower' | 'upper' | 'both' | None]
10641081 Remove edge ticks -- useful for stacked or ganged plots
10651082 where the upper tick of one axes overlaps with the lower
1066- tick of the axes above it. One of 'lower' | 'upper' |
1067- 'both' | None. If prune=='lower', the smallest tick will
1083+ tick of the axes above it.
1084+ If prune=='lower', the smallest tick will
10681085 be removed. If prune=='upper', the largest tick will be
10691086 removed. If prune=='both', the largest and smallest ticks
10701087 will be removed. If prune==None, no ticks will be removed.
10711088
10721089 """
1073- self ._nbins = int (nbins )
1074- self ._trim = trim
1075- self ._integer = integer
1076- self ._symmetric = symmetric
1077- self ._prune = prune
1078- if steps is None :
1079- self ._steps = [1 , 1.5 , 2 , 2.5 , 3 , 4 , 5 , 6 , 8 , 10 ]
1080- else :
1081- if int (steps [- 1 ]) != 10 :
1082- steps = list (steps )
1083- steps .append (10 )
1084- self ._steps = steps
1085- if integer :
1090+ # I left "trim" out; it defaults to True, and it is not
1091+ # clear that there is any use case for False, so we may
1092+ # want to remove that kwarg. EF 2010/04/18
1093+ self .set_params (** self .default_params )
1094+ self .set_params (** kwargs )
1095+
1096+ def set_params (self , ** kwargs ):
1097+ if 'nbins' in kwargs :
1098+ self ._nbins = int (kwargs ['nbins' ])
1099+ if 'trim' in kwargs :
1100+ self ._trim = kwargs ['trim' ]
1101+ if 'integer' in kwargs :
1102+ self ._integer = kwargs ['integer' ]
1103+ if 'symmetric' in kwargs :
1104+ self ._symmetric = kwargs ['symmetric' ]
1105+ if 'prune' in kwargs :
1106+ prune = kwargs ['prune' ]
1107+ if prune is not None and prune not in ['upper' , 'lower' , 'both' ]:
1108+ raise ValueError (
1109+ "prune must be 'upper', 'lower', 'both', or None" )
1110+ self ._prune = prune
1111+ if 'steps' in kwargs :
1112+ steps = kwargs ['steps' ]
1113+ if steps is None :
1114+ self ._steps = [1 , 1.5 , 2 , 2.5 , 3 , 4 , 5 , 6 , 8 , 10 ]
1115+ else :
1116+ if int (steps [- 1 ]) != 10 :
1117+ steps = list (steps )
1118+ steps .append (10 )
1119+ self ._steps = steps
1120+ if 'integer' in kwargs :
1121+ self ._integer = kwargs ['integer' ]
1122+ if self ._integer :
10861123 self ._steps = [n for n in self ._steps if divmod (n ,1 )[1 ] < 0.001 ]
10871124
10881125 def bin_boundaries (self , vmin , vmax ):
0 commit comments