Skip to content

Commit c85444e

Browse files
committed
[#894] Merge commit '4d19db828ea0ee9d3e08b6e767aa2fe0bb163b18' into issue-894
* commit '4d19db828ea0ee9d3e08b6e767aa2fe0bb163b18': Remove anti pattern. Add another test. Use distutils version comparison.
2 parents 90be7ca + 4d19db8 commit c85444e

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

axelrod/plot.py

Lines changed: 4 additions & 10 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
@@ -27,16 +28,9 @@
2728

2829
def default_cmap(version: str = None) -> 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 version is None or LooseVersion(version) >= "1.5":
32+
return 'viridis'
33+
return 'YlGnBu'
4034

4135

4236
class Plot(object):

axelrod/tests/unit/test_plot.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,27 @@ 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')
81+
self.assertEqual(cmap, 'YlGnBu')
82+
83+
cmap = axelrod.plot.default_cmap('1.4.99')
8184
self.assertEqual(cmap, 'YlGnBu')
8285

8386
cmap = axelrod.plot.default_cmap('1.4')
8487
self.assertEqual(cmap, 'YlGnBu')
8588

89+
cmap = axelrod.plot.default_cmap()
90+
self.assertEqual(cmap, 'viridis')
91+
92+
cmap = axelrod.plot.default_cmap('1.5')
93+
self.assertEqual(cmap, 'viridis')
94+
95+
cmap = axelrod.plot.default_cmap('1.5beta')
96+
self.assertEqual(cmap, 'viridis')
97+
8698
cmap = axelrod.plot.default_cmap('1.7')
8799
self.assertEqual(cmap, 'viridis')
88100

0 commit comments

Comments
 (0)