Skip to content

Commit 35e9801

Browse files
committed
Use distutils version comparison.
I also reverted back to use if statements, which felt simpler in this (2 option) case.
1 parent 7d46b8f commit 35e9801

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

axelrod/plot.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import tqdm
44
import warnings
55

6+
from distutils.version import LooseVersion
67
from typing import List, Union
78

89
matplotlib_installed = True
@@ -25,18 +26,11 @@
2526
dataType = List[List[Union[int, float]]]
2627

2728

28-
def default_cmap(version: str = None) -> str:
29+
def default_cmap(version: str = "2.0") -> str:
2930
"""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'
4034

4135

4236
class Plot(object):

axelrod/tests/unit/test_plot.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,24 @@ def setUpClass(cls):
7474
['Defector', 'Tit For Tat', 'Alternator'])
7575

7676
def test_default_cmap(self):
77-
cmap = axelrod.plot.default_cmap()
77+
cmap = axelrod.plot.default_cmap('0.0')
7878
self.assertEqual(cmap, 'YlGnBu')
7979

80-
cmap = axelrod.plot.default_cmap('0.0')
80+
cmap = axelrod.plot.default_cmap('1.3alpha')
8181
self.assertEqual(cmap, 'YlGnBu')
8282

8383
cmap = axelrod.plot.default_cmap('1.4')
8484
self.assertEqual(cmap, 'YlGnBu')
8585

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+
8695
cmap = axelrod.plot.default_cmap('1.7')
8796
self.assertEqual(cmap, 'viridis')
8897

0 commit comments

Comments
 (0)