File tree Expand file tree Collapse file tree 2 files changed +16
-13
lines changed Expand file tree Collapse file tree 2 files changed +16
-13
lines changed Original file line number Diff line number Diff line change 3
3
import tqdm
4
4
import warnings
5
5
6
+ from distutils .version import LooseVersion
6
7
from typing import List , Union
7
8
8
9
matplotlib_installed = True
25
26
dataType = List [List [Union [int , float ]]]
26
27
27
28
28
- def default_cmap (version : str = None ) -> str :
29
+ def default_cmap (version : str = "2.0" ) -> str :
29
30
"""Sets a default matplotlib colormap based on the version."""
30
- version_gt_1_5 = False
31
- if version :
32
- s = version .split ('.' )
33
- version_gt_1_5 = (int (s [0 ]) == 1 and int (s [1 ]) >= 5 ) or (int (s [0 ]) > 1 )
34
-
35
- cmaps = {
36
- True : 'viridis' ,
37
- False : 'YlGnBu'
38
- }
39
- return cmaps [version_gt_1_5 ]
31
+ if LooseVersion (version ) >= "1.5" :
32
+ return 'viridis'
33
+ return 'YlGnBu'
40
34
41
35
42
36
class Plot (object ):
Original file line number Diff line number Diff line change @@ -74,15 +74,24 @@ def setUpClass(cls):
74
74
['Defector' , 'Tit For Tat' , 'Alternator' ])
75
75
76
76
def test_default_cmap (self ):
77
- cmap = axelrod .plot .default_cmap ()
77
+ cmap = axelrod .plot .default_cmap ('0.0' )
78
78
self .assertEqual (cmap , 'YlGnBu' )
79
79
80
- cmap = axelrod .plot .default_cmap ('0.0 ' )
80
+ cmap = axelrod .plot .default_cmap ('1.3alpha ' )
81
81
self .assertEqual (cmap , 'YlGnBu' )
82
82
83
83
cmap = axelrod .plot .default_cmap ('1.4' )
84
84
self .assertEqual (cmap , 'YlGnBu' )
85
85
86
+ cmap = axelrod .plot .default_cmap ()
87
+ self .assertEqual (cmap , 'viridis' )
88
+
89
+ cmap = axelrod .plot .default_cmap ('1.5' )
90
+ self .assertEqual (cmap , 'viridis' )
91
+
92
+ cmap = axelrod .plot .default_cmap ('1.5beta' )
93
+ self .assertEqual (cmap , 'viridis' )
94
+
86
95
cmap = axelrod .plot .default_cmap ('1.7' )
87
96
self .assertEqual (cmap , 'viridis' )
88
97
You can’t perform that action at this time.
0 commit comments