__init__.py
1 """!
2 
3 @brief pyclustering module for cluster analysis.
4 
5 @authors Andrei Novikov (pyclustering@yandex.ru)
6 @date 2014-2019
7 @copyright GNU Public License
8 
9 @cond GNU_PUBLIC_LICENSE
10  PyClustering is free software: you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  PyClustering is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program. If not, see <http://www.gnu.org/licenses/>.
22 @endcond
23 
24 """
25 
26 import itertools
27 import math
28 import warnings
29 
30 try:
31  import matplotlib.pyplot as plt
32  import matplotlib.gridspec as gridspec
33 except Exception:
34  warnings.warn("Impossible to import matplotlib (please, install 'matplotlib'), pyclustering's visualization "
35  "functionality is not available.")
36 
37 from pyclustering.utils.color import color as color_list
38 
39 
41  """!
42  @brief Description of cluster for representation on canvas.
43 
44  """
45 
46  def __init__(self, cluster, data, marker, markersize, color):
47  """!
48  @brief Constructor of cluster representation on the canvas.
49 
50  @param[in] cluster (list): Single cluster that consists of objects or indexes from data.
51  @param[in] data (list): Objects that should be displayed, can be None if clusters consist of objects instead of indexes.
52  @param[in] marker (string): Type of marker that is used for drawing objects.
53  @param[in] markersize (uint): Size of marker that is used for drawing objects.
54  @param[in] color (string): Color of the marker that is used for drawing objects.
55 
56  """
57 
58  self.cluster = cluster
59 
60 
61  self.data = data
62 
63 
64  self.marker = marker
65 
66 
67  self.markersize = markersize
68 
69 
70  self.color = color
71 
72 
73  self.attributes = []
74 
75 
76 
78  """!
79  @brief Visualizer for cluster in multi-dimensional data.
80  @details This cluster visualizer is useful for clusters in data whose dimension is greater than 3. The
81  multidimensional visualizer helps to overcome 'cluster_visualizer' shortcoming - ability to display
82  clusters in 1D, 2D or 3D dimensional data space.
83 
84  Example of clustering results visualization where 'Iris' is used:
85  @code
86  from pyclustering.utils import read_sample
87  from pyclustering.samples.definitions import FAMOUS_SAMPLES
88  from pyclustering.cluster import cluster_visualizer_multidim
89 
90  # load 4D data sample 'Iris'
91  sample_4d = read_sample(FAMOUS_SAMPLES.SAMPLE_IRIS)
92 
93  # initialize 3 initial centers using K-Means++ algorithm
94  centers = kmeans_plusplus_initializer(sample_4d, 3).initialize()
95 
96  # performs cluster analysis using X-Means
97  xmeans_instance = xmeans(sample_4d, centers)
98  xmeans_instance.process()
99  clusters = xmeans_instance.get_clusters()
100 
101  # visualize obtained clusters in multi-dimensional space
102  visualizer = cluster_visualizer_multidim()
103  visualizer.append_clusters(clusters, sample_4d)
104  visualizer.show(max_row_size=3)
105  @endcode
106 
107  Visualized clustering results of 'Iris' data (multi-dimensional data):
108  @image html xmeans_clustering_famous_iris.png "Fig. 1. X-Means clustering results (data 'Iris')."
109 
110  Sometimes no need to display results in all dimensions. Parameter 'filter' can be used to display only
111  interesting coordinate pairs. Here is an example of visualization of pair coordinates (x0, x1) and (x0, x2) for
112  previous clustering results:
113  @code
114  visualizer = cluster_visualizer_multidim()
115  visualizer.append_clusters(clusters, sample_4d)
116  visualizer.show(pair_filter=[[0, 1], [0, 2]])
117  @endcode
118 
119  Visualized results of specified coordinate pairs:
120  @image html xmeans_clustering_famous_iris_filtered.png "Fig. 2. X-Means clustering results (x0, x1) and (x0, x2) (data 'Iris')."
121 
122  """
123 
124  def __init__(self):
125  """!
126  @brief Constructs cluster visualizer for multidimensional data.
127  @details The visualizer is suitable more data whose dimension is bigger than 3.
128 
129  """
130  self.__clusters = []
131  self.__figure = None
132  self.__grid_spec = None
133 
134 
135  def append_cluster(self, cluster, data = None, marker = '.', markersize = None, color = None):
136  """!
137  @brief Appends cluster for visualization.
138 
139  @param[in] cluster (list): cluster that may consist of indexes of objects from the data or object itself.
140  @param[in] data (list): If defines that each element of cluster is considered as a index of object from the data.
141  @param[in] marker (string): Marker that is used for displaying objects from cluster on the canvas.
142  @param[in] markersize (uint): Size of marker.
143  @param[in] color (string): Color of marker.
144 
145  @return Returns index of cluster descriptor on the canvas.
146 
147  """
148  if len(cluster) == 0:
149  raise ValueError("Empty cluster is provided.")
150 
151  markersize = markersize or 5
152  if color is None:
153  index_color = len(self.__clusters) % len(color_list.TITLES)
154  color = color_list.TITLES[index_color]
155 
156  cluster_descriptor = canvas_cluster_descr(cluster, data, marker, markersize, color)
157  self.__clusters.append(cluster_descriptor)
158 
159 
160  def append_clusters(self, clusters, data=None, marker='.', markersize=None):
161  """!
162  @brief Appends list of cluster for visualization.
163 
164  @param[in] clusters (list): List of clusters where each cluster may consist of indexes of objects from the data or object itself.
165  @param[in] data (list): If defines that each element of cluster is considered as a index of object from the data.
166  @param[in] marker (string): Marker that is used for displaying objects from clusters on the canvas.
167  @param[in] markersize (uint): Size of marker.
168 
169  """
170 
171  for cluster in clusters:
172  self.append_cluster(cluster, data, marker, markersize)
173 
174 
175  def show(self, pair_filter=None, **kwargs):
176  """!
177  @brief Shows clusters (visualize) in multi-dimensional space.
178 
179  @param[in] pair_filter (list): List of coordinate pairs that should be displayed. This argument is used as a filter.
180  @param[in] **kwargs: Arbitrary keyword arguments (available arguments: 'visible_axis' 'visible_labels', 'visible_grid', 'row_size').
181 
182  <b>Keyword Args:</b><br>
183  - visible_axis (bool): Defines visibility of axes on each canvas, if True - axes are visible.
184  By default axis of each canvas are not displayed.
185  - visible_labels (bool): Defines visibility of labels on each canvas, if True - labels is displayed.
186  By default labels of each canvas are displayed.
187  - visible_grid (bool): Defines visibility of grid on each canvas, if True - grid is displayed.
188  By default grid of each canvas is displayed.
189  - max_row_size (uint): Maximum number of canvases on one row.
190 
191  """
192 
193  if not len(self.__clusters) > 0:
194  raise ValueError("There is no non-empty clusters for visualization.")
195 
196  cluster_data = self.__clusters[0].data or self.__clusters[0].cluster
197  dimension = len(cluster_data[0])
198 
199  acceptable_pairs = pair_filter or []
200  pairs = []
201  amount_axis = 1
202  axis_storage = []
203 
204  if dimension > 1:
205  pairs = self.__create_pairs(dimension, acceptable_pairs)
206  amount_axis = len(pairs)
207 
208  self.__figure = plt.figure()
209  self.__grid_spec = self.__create_grid_spec(amount_axis, kwargs.get('max_row_size', 4))
210 
211  for index in range(amount_axis):
212  ax = self.__create_canvas(dimension, pairs, index, **kwargs)
213  axis_storage.append(ax)
214 
215  for cluster_descr in self.__clusters:
216  self.__draw_canvas_cluster(axis_storage, cluster_descr, pairs)
217 
218  plt.show()
219 
220 
221  def __create_grid_spec(self, amount_axis, max_row_size):
222  """!
223  @brief Create grid specification for figure to place canvases.
224 
225  @param[in] amount_axis (uint): Amount of canvases that should be organized by the created grid specification.
226  @param[in] max_row_size (max_row_size): Maximum number of canvases on one row.
227 
228  @return (gridspec.GridSpec) Grid specification to place canvases on figure.
229 
230  """
231  row_size = amount_axis
232  if row_size > max_row_size:
233  row_size = max_row_size
234 
235  col_size = math.ceil(amount_axis / row_size)
236  return gridspec.GridSpec(col_size, row_size)
237 
238 
239  def __create_pairs(self, dimension, acceptable_pairs):
240  """!
241  @brief Create coordinate pairs that should be displayed.
242 
243  @param[in] dimension (uint): Data-space dimension.
244  @param[in] acceptable_pairs (list): List of coordinate pairs that should be displayed.
245 
246  @return (list) List of coordinate pairs that should be displayed.
247 
248  """
249  if len(acceptable_pairs) > 0:
250  return acceptable_pairs
251 
252  return list(itertools.combinations(range(dimension), 2))
253 
254 
255  def __create_canvas(self, dimension, pairs, position, **kwargs):
256  """!
257  @brief Create new canvas with user defined parameters to display cluster or chunk of cluster on it.
258 
259  @param[in] dimension (uint): Data-space dimension.
260  @param[in] pairs (list): Pair of coordinates that will be displayed on the canvas. If empty than label will not
261  be displayed on the canvas.
262  @param[in] position (uint): Index position of canvas on a grid.
263  @param[in] **kwargs: Arbitrary keyword arguments (available arguments: 'visible_axis' 'visible_labels', 'visible_grid').
264 
265  <b>Keyword Args:</b><br>
266  - visible_axis (bool): Defines visibility of axes on each canvas, if True - axes are visible.
267  By default axis are not displayed.
268  - visible_labels (bool): Defines visibility of labels on each canvas, if True - labels is displayed.
269  By default labels are displayed.
270  - visible_grid (bool): Defines visibility of grid on each canvas, if True - grid is displayed.
271  By default grid is displayed.
272 
273  @return (matplotlib.Axis) Canvas to display cluster of chuck of cluster.
274 
275  """
276  visible_grid = kwargs.get('visible_grid', True)
277  visible_labels = kwargs.get('visible_labels', True)
278  visible_axis = kwargs.get('visible_axis', False)
279 
280  ax = self.__figure.add_subplot(self.__grid_spec[position])
281 
282  if dimension > 1:
283  if visible_labels:
284  ax.set_xlabel("x%d" % pairs[position][0])
285  ax.set_ylabel("x%d" % pairs[position][1])
286  else:
287  ax.set_ylim(-0.5, 0.5)
288  ax.set_yticklabels([])
289 
290  if visible_grid:
291  ax.grid(True)
292 
293  if not visible_axis:
294  ax.set_yticklabels([])
295  ax.set_xticklabels([])
296 
297  return ax
298 
299 
300  def __draw_canvas_cluster(self, axis_storage, cluster_descr, pairs):
301  """!
302  @brief Draw clusters.
303 
304  @param[in] axis_storage (list): List of matplotlib axis where cluster dimensional chunks are displayed.
305  @param[in] cluster_descr (canvas_cluster_descr): Canvas cluster descriptor that should be displayed.
306  @param[in] pairs (list): List of coordinates that should be displayed.
307 
308  """
309 
310  for index_axis in range(len(axis_storage)):
311  for item in cluster_descr.cluster:
312  if len(pairs) > 0:
313  self.__draw_cluster_item_multi_dimension(axis_storage[index_axis], pairs[index_axis], item, cluster_descr)
314  else:
315  self.__draw_cluster_item_one_dimension(axis_storage[index_axis], item, cluster_descr)
316 
317 
318  def __draw_cluster_item_multi_dimension(self, ax, pair, item, cluster_descr):
319  """!
320  @brief Draw cluster chunk defined by pair coordinates in data space with dimension greater than 1.
321 
322  @param[in] ax (axis): Matplotlib axis that is used to display chunk of cluster point.
323  @param[in] pair (list): Coordinate of the point that should be displayed.
324  @param[in] item (list): Data point or index of data point.
325  @param[in] cluster_descr (canvas_cluster_descr): Cluster description whose point is visualized.
326 
327  """
328 
329  index_dimension1 = pair[0]
330  index_dimension2 = pair[1]
331 
332  if cluster_descr.data is None:
333  ax.plot(item[index_dimension1], item[index_dimension2],
334  color=cluster_descr.color, marker=cluster_descr.marker, markersize=cluster_descr.markersize)
335  else:
336  ax.plot(cluster_descr.data[item][index_dimension1], cluster_descr.data[item][index_dimension2],
337  color=cluster_descr.color, marker=cluster_descr.marker, markersize=cluster_descr.markersize)
338 
339 
340  def __draw_cluster_item_one_dimension(self, ax, item, cluster_descr):
341  """!
342  @brief Draw cluster point in one dimensional data space..
343 
344  @param[in] ax (axis): Matplotlib axis that is used to display chunk of cluster point.
345  @param[in] item (list): Data point or index of data point.
346  @param[in] cluster_descr (canvas_cluster_descr): Cluster description whose point is visualized.
347 
348  """
349 
350  if cluster_descr.data is None:
351  ax.plot(item[0], 0.0,
352  color=cluster_descr.color, marker=cluster_descr.marker, markersize=cluster_descr.markersize)
353  else:
354  ax.plot(cluster_descr.data[item][0], 0.0,
355  color=cluster_descr.color, marker=cluster_descr.marker, markersize=cluster_descr.markersize)
356 
357 
358 
360  """!
361  @brief Common visualizer of clusters on 1D, 2D or 3D surface.
362  @details Use 'cluster_visualizer_multidim' visualizer in case of data dimension is greater than 3.
363 
364  @see cluster_visualizer_multidim
365 
366  """
367 
368  def __init__(self, number_canvases = 1, size_row = 1, titles = None):
369  """!
370  @brief Constructor of cluster visualizer.
371 
372  @param[in] number_canvases (uint): Number of canvases that is used for visualization.
373  @param[in] size_row (uint): Amount of canvases that can be placed in one row.
374  @param[in] titles (list): List of canvas's titles.
375 
376  Example:
377  @code
378  # load 2D data sample
379  sample_2d = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE1);
380 
381  # load 3D data sample
382  sample_3d = read_sample(FCPS_SAMPLES.SAMPLE_HEPTA);
383 
384  # extract clusters from the first sample using DBSCAN algorithm
385  dbscan_instance = dbscan(sample_2d, 0.4, 2, False);
386  dbscan_instance.process();
387  clusters_sample_2d = dbscan_instance.get_clusters();
388 
389  # extract clusters from the second sample using DBSCAN algorithm
390  dbscan_instance = dbscan(sample_3d, 1, 3, True);
391  dbscan_instance.process();
392  clusters_sample_3d = dbscan_instance.get_clusters();
393 
394  # create plot with two canvases where each row contains 2 canvases.
395  size = 2;
396  row_size = 2;
397  visualizer = cluster_visualizer(size, row_size);
398 
399  # place clustering result of sample_2d to the first canvas
400  visualizer.append_clusters(clusters_sample_2d, sample_2d, 0, markersize = 5);
401 
402  # place clustering result of sample_3d to the second canvas
403  visualizer.append_clusters(clusters_sample_3d, sample_3d, 1, markersize = 30);
404 
405  # show plot
406  visualizer.show();
407  @endcode
408 
409  """
410 
411  self.__number_canvases = number_canvases
412  self.__size_row = size_row
413  self.__canvas_clusters = [ [] for _ in range(number_canvases) ]
414  self.__canvas_dimensions = [ None for _ in range(number_canvases) ]
415  self.__canvas_titles = [ None for _ in range(number_canvases) ]
416 
417  if titles is not None:
418  self.__canvas_titles = titles
419 
420  self.__default_2d_marker_size = 5
421  self.__default_3d_marker_size = 30
422 
423 
424  def append_cluster(self, cluster, data=None, canvas=0, marker='.', markersize=None, color=None):
425  """!
426  @brief Appends cluster to canvas for drawing.
427 
428  @param[in] cluster (list): cluster that may consist of indexes of objects from the data or object itself.
429  @param[in] data (list): If defines that each element of cluster is considered as a index of object from the data.
430  @param[in] canvas (uint): Number of canvas that should be used for displaying cluster.
431  @param[in] marker (string): Marker that is used for displaying objects from cluster on the canvas.
432  @param[in] markersize (uint): Size of marker.
433  @param[in] color (string): Color of marker.
434 
435  @return Returns index of cluster descriptor on the canvas.
436 
437  """
438 
439  if len(cluster) == 0:
440  return
441 
442  if canvas > self.__number_canvases or canvas < 0:
443  raise ValueError("Canvas index '%d' is out of range [0; %d]." % self.__number_canvases or canvas)
444 
445  if color is None:
446  index_color = len(self.__canvas_clusters[canvas]) % len(color_list.TITLES)
447  color = color_list.TITLES[index_color]
448 
449  added_canvas_descriptor = canvas_cluster_descr(cluster, data, marker, markersize, color)
450  self.__canvas_clusters[canvas].append( added_canvas_descriptor )
451 
452  if data is None:
453  dimension = len(cluster[0])
454  if self.__canvas_dimensions[canvas] is None:
455  self.__canvas_dimensions[canvas] = dimension
456  elif self.__canvas_dimensions[canvas] != dimension:
457  raise ValueError("Only clusters with the same dimension of objects can be displayed on canvas.")
458 
459  else:
460  dimension = len(data[0])
461  if self.__canvas_dimensions[canvas] is None:
462  self.__canvas_dimensions[canvas] = dimension
463  elif self.__canvas_dimensions[canvas] != dimension:
464  raise ValueError("Only clusters with the same dimension of objects can be displayed on canvas.")
465 
466  if (dimension < 1) or (dimension > 3):
467  raise ValueError("Only objects with size dimension 1 (1D plot), 2 (2D plot) or 3 (3D plot) "
468  "can be displayed. For multi-dimensional data use 'cluster_visualizer_multidim'.")
469 
470  if markersize is None:
471  if (dimension == 1) or (dimension == 2):
472  added_canvas_descriptor.markersize = self.__default_2d_marker_size
473  elif dimension == 3:
474  added_canvas_descriptor.markersize = self.__default_3d_marker_size
475 
476  return len(self.__canvas_clusters[canvas]) - 1
477 
478 
479  def append_cluster_attribute(self, index_canvas, index_cluster, data, marker = None, markersize = None):
480  """!
481  @brief Append cluster attribure for cluster on specific canvas.
482  @details Attribute it is data that is visualized for specific cluster using its color, marker and markersize if last two is not specified.
483 
484  @param[in] index_canvas (uint): Index canvas where cluster is located.
485  @param[in] index_cluster (uint): Index cluster whose attribute should be added.
486  @param[in] data (list): List of points (data) that represents attribute.
487  @param[in] marker (string): Marker that is used for displaying objects from cluster on the canvas.
488  @param[in] markersize (uint): Size of marker.
489 
490  """
491 
492  cluster_descr = self.__canvas_clusters[index_canvas][index_cluster]
493  attribute_marker = marker
494  if attribute_marker is None:
495  attribute_marker = cluster_descr.marker
496 
497  attribure_markersize = markersize
498  if attribure_markersize is None:
499  attribure_markersize = cluster_descr.markersize
500 
501  attribute_color = cluster_descr.color
502 
503  added_attribute_cluster_descriptor = canvas_cluster_descr(data, None, attribute_marker, attribure_markersize, attribute_color)
504  self.__canvas_clusters[index_canvas][index_cluster].attributes.append(added_attribute_cluster_descriptor)
505 
506 
507  def append_clusters(self, clusters, data = None, canvas = 0, marker = '.', markersize = None):
508  """!
509  @brief Appends list of cluster to canvas for drawing.
510 
511  @param[in] clusters (list): List of clusters where each cluster may consist of indexes of objects from the data or object itself.
512  @param[in] data (list): If defines that each element of cluster is considered as a index of object from the data.
513  @param[in] canvas (uint): Number of canvas that should be used for displaying clusters.
514  @param[in] marker (string): Marker that is used for displaying objects from clusters on the canvas.
515  @param[in] markersize (uint): Size of marker.
516 
517  """
518 
519  for cluster in clusters:
520  self.append_cluster(cluster, data, canvas, marker, markersize)
521 
522 
523  def set_canvas_title(self, text, canvas = 0):
524  """!
525  @brief Set title for specified canvas.
526 
527  @param[in] text (string): Title for canvas.
528  @param[in] canvas (uint): Index of canvas where title should be displayed.
529 
530  """
531 
532  if canvas > self.__number_canvases:
533  raise NameError('Canvas does ' + canvas + ' not exists.')
534 
535  self.__canvas_titles[canvas] = text
536 
537 
538  def get_cluster_color(self, index_cluster, index_canvas):
539  """!
540  @brief Returns cluster color on specified canvas.
541 
542  """
543  return self.__canvas_clusters[index_canvas][index_cluster].color
544 
545 
546  def show(self, figure=None, invisible_axis=True, visible_grid=True, display=True, shift=None):
547  """!
548  @brief Shows clusters (visualize).
549 
550  @param[in] figure (fig): Defines requirement to use specified figure, if None - new figure is created for drawing clusters.
551  @param[in] invisible_axis (bool): Defines visibility of axes on each canvas, if True - axes are invisible.
552  @param[in] visible_grid (bool): Defines visibility of grid on each canvas, if True - grid is displayed.
553  @param[in] display (bool): Defines requirement to display clusters on a stage, if True - clusters are displayed,
554  if False - plt.show() should be called by user."
555  @param[in] shift (uint): Force canvas shift value - defines canvas index from which custers should be visualized.
556 
557  @return (fig) Figure where clusters are shown.
558 
559  """
560 
561  canvas_shift = shift
562  if canvas_shift is None:
563  if figure is not None:
564  canvas_shift = len(figure.get_axes())
565  else:
566  canvas_shift = 0
567 
568  if figure is not None:
569  cluster_figure = figure
570  else:
571  cluster_figure = plt.figure()
572 
573  maximum_cols = self.__size_row
574  maximum_rows = math.ceil( (self.__number_canvases + canvas_shift) / maximum_cols)
575 
576  grid_spec = gridspec.GridSpec(maximum_rows, maximum_cols)
577 
578  for index_canvas in range(len(self.__canvas_clusters)):
579  canvas_data = self.__canvas_clusters[index_canvas]
580  if len(canvas_data) == 0:
581  continue
582 
583  dimension = self.__canvas_dimensions[index_canvas]
584 
585  #ax = axes[real_index];
586  if (dimension == 1) or (dimension == 2):
587  ax = cluster_figure.add_subplot(grid_spec[index_canvas + canvas_shift])
588  else:
589  ax = cluster_figure.add_subplot(grid_spec[index_canvas + canvas_shift], projection='3d')
590 
591  if len(canvas_data) == 0:
592  plt.setp(ax, visible=False)
593 
594  for cluster_descr in canvas_data:
595  self.__draw_canvas_cluster(ax, dimension, cluster_descr)
596 
597  for attribute_descr in cluster_descr.attributes:
598  self.__draw_canvas_cluster(ax, dimension, attribute_descr)
599 
600  if invisible_axis is True:
601  ax.xaxis.set_ticklabels([])
602  ax.yaxis.set_ticklabels([])
603 
604  if (dimension == 3):
605  ax.zaxis.set_ticklabels([])
606 
607  if self.__canvas_titles[index_canvas] is not None:
608  ax.set_title(self.__canvas_titles[index_canvas])
609 
610  ax.grid(visible_grid)
611 
612  if display is True:
613  plt.show()
614 
615  return cluster_figure
616 
617 
618  def __draw_canvas_cluster(self, ax, dimension, cluster_descr):
619  """!
620  @brief Draw canvas cluster descriptor.
621 
622  @param[in] ax (Axis): Axis of the canvas where canvas cluster descriptor should be displayed.
623  @param[in] dimension (uint): Canvas dimension.
624  @param[in] cluster_descr (canvas_cluster_descr): Canvas cluster descriptor that should be displayed.
625 
626  @return (fig) Figure where clusters are shown.
627 
628  """
629 
630  cluster = cluster_descr.cluster
631  data = cluster_descr.data
632  marker = cluster_descr.marker
633  markersize = cluster_descr.markersize
634  color = cluster_descr.color
635 
636  for item in cluster:
637  if dimension == 1:
638  if data is None:
639  ax.plot(item[0], 0.0, color = color, marker = marker, markersize = markersize)
640  else:
641  ax.plot(data[item][0], 0.0, color = color, marker = marker, markersize = markersize)
642 
643  elif dimension == 2:
644  if data is None:
645  ax.plot(item[0], item[1], color = color, marker = marker, markersize = markersize)
646  else:
647  ax.plot(data[item][0], data[item][1], color = color, marker = marker, markersize = markersize)
648 
649  elif dimension == 3:
650  if data is None:
651  ax.scatter(item[0], item[1], item[2], c = color, marker = marker, s = markersize)
652  else:
653  ax.scatter(data[item][0], data[item][1], data[item][2], c = color, marker = marker, s = markersize)
def show(self, figure=None, invisible_axis=True, visible_grid=True, display=True, shift=None)
Shows clusters (visualize).
Definition: __init__.py:546
Common visualizer of clusters on 1D, 2D or 3D surface.
Definition: __init__.py:359
def append_cluster(self, cluster, data=None, canvas=0, marker='.', markersize=None, color=None)
Appends cluster to canvas for drawing.
Definition: __init__.py:424
def get_cluster_color(self, index_cluster, index_canvas)
Returns cluster color on specified canvas.
Definition: __init__.py:538
def append_cluster(self, cluster, data=None, marker='.', markersize=None, color=None)
Appends cluster for visualization.
Definition: __init__.py:135
def set_canvas_title(self, text, canvas=0)
Set title for specified canvas.
Definition: __init__.py:523
def __init__(self)
Constructs cluster visualizer for multidimensional data.
Definition: __init__.py:124
def __create_canvas(self, dimension, pairs, position, kwargs)
Create new canvas with user defined parameters to display cluster or chunk of cluster on it...
Definition: __init__.py:255
def append_cluster_attribute(self, index_canvas, index_cluster, data, marker=None, markersize=None)
Append cluster attribure for cluster on specific canvas.
Definition: __init__.py:479
markersize
Size of marker that is used for drawing objects.
Definition: __init__.py:67
data
Data where objects are stored.
Definition: __init__.py:61
def show(self, pair_filter=None, kwargs)
Shows clusters (visualize) in multi-dimensional space.
Definition: __init__.py:175
def __draw_canvas_cluster(self, ax, dimension, cluster_descr)
Draw canvas cluster descriptor.
Definition: __init__.py:618
Colors used by pyclustering library for visualization.
Definition: color.py:1
def __create_grid_spec(self, amount_axis, max_row_size)
Create grid specification for figure to place canvases.
Definition: __init__.py:221
def __init__(self, cluster, data, marker, markersize, color)
Constructor of cluster representation on the canvas.
Definition: __init__.py:46
marker
Marker that is used for drawing objects.
Definition: __init__.py:64
attributes
Attribures of the clusters - additional collections of data points that are regarded to the cluster...
Definition: __init__.py:73
def append_clusters(self, clusters, data=None, marker='.', markersize=None)
Appends list of cluster for visualization.
Definition: __init__.py:160
def __draw_cluster_item_multi_dimension(self, ax, pair, item, cluster_descr)
Draw cluster chunk defined by pair coordinates in data space with dimension greater than 1...
Definition: __init__.py:318
def __draw_cluster_item_one_dimension(self, ax, item, cluster_descr)
Draw cluster point in one dimensional data space.
Definition: __init__.py:340
Description of cluster for representation on canvas.
Definition: __init__.py:40
def __init__(self, number_canvases=1, size_row=1, titles=None)
Constructor of cluster visualizer.
Definition: __init__.py:368
Visualizer for cluster in multi-dimensional data.
Definition: __init__.py:77
cluster
Cluster that may consist of objects or indexes of objects from data.
Definition: __init__.py:58
def append_clusters(self, clusters, data=None, canvas=0, marker='.', markersize=None)
Appends list of cluster to canvas for drawing.
Definition: __init__.py:507
color
Color that is used for coloring marker.
Definition: __init__.py:70
def __create_pairs(self, dimension, acceptable_pairs)
Create coordinate pairs that should be displayed.
Definition: __init__.py:239
def __draw_canvas_cluster(self, axis_storage, cluster_descr, pairs)
Draw clusters.
Definition: __init__.py:300