Skip to content

Commit

Permalink
Remove distutils usage in plot.py since it's not available in Python …
Browse files Browse the repository at this point in the history
…3.12
  • Loading branch information
marcharper committed Mar 8, 2024
1 parent 515b918 commit 5f06548
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 38 deletions.
11 changes: 1 addition & 10 deletions axelrod/plot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pathlib
from distutils.version import LooseVersion
from typing import List, Union

import matplotlib
Expand All @@ -16,13 +15,6 @@
dataType = List[List[Union[int, float]]]


def default_cmap(version: str = "2.0") -> str:
"""Sets a default matplotlib colormap based on the version."""
if LooseVersion(version) >= "1.5":
return "viridis"
return "YlGnBu"


class Plot(object):
def __init__(self, result_set: ResultSet) -> None:
self.result_set = result_set
Expand Down Expand Up @@ -184,6 +176,7 @@ def _payoff_heatmap(
names: namesType,
title: titleType = None,
ax: matplotlib.axes.SubplotBase = None,
cmap: str = 'viridis'
) -> matplotlib.figure.Figure:
"""Generic heatmap plot"""

Expand All @@ -196,8 +189,6 @@ def _payoff_heatmap(
width = max(self.num_players / 4, 12)
height = width
figure.set_size_inches(width, height)
matplotlib_version = matplotlib.__version__
cmap = default_cmap(matplotlib_version)
mat = ax.matshow(data, cmap=cmap)
ax.set_xticks(range(self.result_set.num_players))
ax.set_yticks(range(self.result_set.num_players))
Expand Down
28 changes: 0 additions & 28 deletions axelrod/tests/unit/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,34 +75,6 @@ def setUpClass(cls):
["Defector", "Tit For Tat", "Alternator"],
)

def test_default_cmap(self):
cmap = axl.plot.default_cmap("0.0")
self.assertEqual(cmap, "YlGnBu")

cmap = axl.plot.default_cmap("1.3alpha")
self.assertEqual(cmap, "YlGnBu")

cmap = axl.plot.default_cmap("1.4.99")
self.assertEqual(cmap, "YlGnBu")

cmap = axl.plot.default_cmap("1.4")
self.assertEqual(cmap, "YlGnBu")

cmap = axl.plot.default_cmap()
self.assertEqual(cmap, "viridis")

cmap = axl.plot.default_cmap("1.5")
self.assertEqual(cmap, "viridis")

cmap = axl.plot.default_cmap("1.5beta")
self.assertEqual(cmap, "viridis")

cmap = axl.plot.default_cmap("1.7")
self.assertEqual(cmap, "viridis")

cmap = axl.plot.default_cmap("2.0")
self.assertEqual(cmap, "viridis")

def test_init(self):
plot = axl.Plot(self.test_result_set)
self.assertEqual(plot.result_set, self.test_result_set)
Expand Down

0 comments on commit 5f06548

Please sign in to comment.