mapclassify allows for user defined formatting of legends
import mapclassify
mapclassify.__version__
'2.3.0'
cal = mapclassify.load_example()
q6 = mapclassify.Quantiles(cal, k=6)
q6
Quantiles Interval Count -------------------------- [ 0.13, 1.16] | 10 ( 1.16, 3.38] | 10 ( 3.38, 9.36] | 9 ( 9.36, 24.32] | 10 ( 24.32, 70.78] | 9 ( 70.78, 4111.45] | 10
The default is to use two decimal places for this dataset.
If the user desires a list of strings with these values, the get_legend_classes
method can be called
which will return the strings with the default format:
q6.get_legend_classes()
['[ 0.13, 1.16]', '( 1.16, 3.38]', '( 3.38, 9.36]', '( 9.36, 24.32]', '( 24.32, 70.78]', '( 70.78, 4111.45]']
To set the legends to integers, an option can be passed into the method:
q6.get_legend_classes(fmt="{:.0f}")
['[ 0, 1]', '( 1, 3]', '( 3, 9]', '( 9, 24]', '( 24, 71]', '( 71, 4111]']
Note that this does not change the original object:
q6
Quantiles Interval Count -------------------------- [ 0.13, 1.16] | 10 ( 1.16, 3.38] | 10 ( 3.38, 9.36] | 9 ( 9.36, 24.32] | 10 ( 24.32, 70.78] | 9 ( 70.78, 4111.45] | 10
The format can be changed on the object by calling the set_fmt
method:
q6.set_fmt(fmt="{:.0f}")
q6
Quantiles Interval Count -------------------- [ 0, 1] | 10 ( 1, 3] | 10 ( 3, 9] | 9 ( 9, 24] | 10 ( 24, 71] | 9 ( 71, 4111] | 10