Skip to content

Commit 3119c9d

Browse files
committed
Violon plots only
Assuming that the latest version of matplotib is installable.
1 parent 6ea09d3 commit 3119c9d

File tree

1 file changed

+3
-42
lines changed

1 file changed

+3
-42
lines changed

axelrod/plot.py

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from numpy.linalg import LinAlgError
21
from numpy import arange, median, nan_to_num
32
from warnings import warn
43

@@ -27,23 +26,6 @@ def __init__(self, result_set):
2726
self.result_set = result_set
2827
self.matplotlib_installed = matplotlib_installed
2928

30-
# Abstract Box and Violin plots
31-
32-
def _boxplot(self, data, names, title=None):
33-
"""For making boxplots."""
34-
if not self.matplotlib_installed:
35-
return None
36-
nplayers = self.result_set.nplayers
37-
width = max(nplayers / 3, 12)
38-
height = width / 2
39-
figure = plt.figure(figsize=(width, height))
40-
plt.boxplot(data)
41-
plt.xticks(self._boxplot_xticks_locations, names, rotation=90)
42-
plt.tick_params(axis='both', which='both', labelsize=8)
43-
if title:
44-
plt.title(title)
45-
return figure
46-
4729
def _violinplot(self, data, names, title=None):
4830
"""For making violinplots."""
4931
if not self.matplotlib_installed:
@@ -83,14 +65,7 @@ def boxplot(self, title=None):
8365
"""For the specific mean score boxplot."""
8466
data = self._boxplot_dataset
8567
names = self._boxplot_xticks_labels
86-
try:
87-
figure = self._violinplot(data, names, title=title)
88-
except LinAlgError:
89-
# Matplotlib doesn't handle single point distributions well
90-
# in violin plots. Should be fixed in next release:
91-
# https://github.com/matplotlib/matplotlib/pull/4816
92-
# Fall back to boxplot
93-
figure = self._boxplot(data, names, title=title)
68+
figure = self._violinplot(data, names, title=title)
9469
return figure
9570

9671
@property
@@ -112,14 +87,7 @@ def winplot(self, title=None):
11287
return None
11388

11489
data, names = self._winplot_dataset
115-
try:
116-
figure = self._violinplot(data, names, title)
117-
except LinAlgError:
118-
# Matplotlib doesn't handle single point distributions well
119-
# in violin plots. Should be fixed in next release:
120-
# https://github.com/matplotlib/matplotlib/pull/4816
121-
# Fall back to boxplot
122-
figure = self._boxplot(data, names, title)
90+
figure = self._violinplot(data, names, title)
12391
# Expand ylim a bit
12492
maximum = max(max(w) for w in data)
12593
plt.ylim(-0.5, 0.5 + maximum)
@@ -165,14 +133,7 @@ def lengthplot(self, title=None):
165133
"""For the specific match length boxplot."""
166134
data = self._lengthplot_dataset
167135
names = self._boxplot_xticks_labels
168-
try:
169-
figure = self._violinplot(data, names, title=title)
170-
except LinAlgError:
171-
# Matplotlib doesn't handle single point distributions well
172-
# in violin plots. Should be fixed in next release:
173-
# https://github.com/matplotlib/matplotlib/pull/4816
174-
# Fall back to boxplot
175-
figure = self._boxplot(data, names, title=title)
136+
figure = self._violinplot(data, names, title=title)
176137
return figure
177138

178139
# Payoff heatmaps

0 commit comments

Comments
 (0)