Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions pyswarms/utils/plotters/plotters.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,26 @@ def plot_cost_history(
return ax


def _check_pos_history(pos_history):
"""Check the dimension of the position history before plotting

Parameters
----------
pos_history : numpy.ndarray or list
Position history of the swarm with shape
:code:`(iteration, n_particles, dimensions)`

Returns
-------
None
"""
if np.array(pos_history).shape[1] > 2:
print(
"""Warning! This method is suited for plotting a 2-dimensional position history.
Other dimensions beyond the first two will not be plotted."""
)


def plot_contour(
pos_history,
canvas=None,
Expand Down Expand Up @@ -187,6 +207,7 @@ def plot_contour(
The drawn animation that can be saved to mp4 or other
third-party tools
"""
_check_pos_history(pos_history)

try:
# If no Designer class supplied, use defaults
Expand Down Expand Up @@ -324,6 +345,8 @@ def plot_surface(
The drawn animation that can be saved to mp4 or other
third-party tools
"""
_check_pos_history(pos_history)

try:
# If no Designer class supplied, use defaults
if designer is None:
Expand Down