Skip to content

Commit 0246a80

Browse files
committed
Fix a bug in Matplotlib parameter
1 parent 4a80e07 commit 0246a80

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# =============================================================================
2+
# Python Compiled Files: Machine-generated bytecode that speeds up execution.
3+
# These vary by OS and Python version, so they should never be committed.
4+
# =============================================================================
5+
# Folders containing .pyc files (e.g., views.cpython-312.pyc)
6+
# Matches .pyc (compiled), .pyo (optimized), and .pyd (Windows DLLs)
7+
# Compiled Java class files generated by Jython
8+
__pycache__/
9+
*.py[cod]
10+
*$py.class

pygad/visualize/plot.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,19 @@ def plot_genes(self,
322322

323323
# Create an axes instance
324324
ax = fig.add_subplot(111)
325-
boxeplots = ax.boxplot(solutions_to_plot,
326-
labels=range(self.num_genes),
327-
patch_artist=True)
325+
# Matplotlib 3.9 renamed the boxplot `labels=` kwarg to
326+
# `tick_labels=` and will drop the old name in 3.11. Use whichever
327+
# name this matplotlib supports so we work on either side of the
328+
# rename without forcing users to upgrade matplotlib.
329+
import inspect
330+
_tick_kw = (
331+
"tick_labels"
332+
if "tick_labels" in inspect.signature(ax.boxplot).parameters
333+
else "labels"
334+
)
335+
boxeplots = ax.boxplot(solutions_to_plot,
336+
patch_artist=True,
337+
**{_tick_kw: range(self.num_genes)})
328338
# adding horizontal grid lines
329339
ax.yaxis.grid(True)
330340

0 commit comments

Comments
 (0)