pyclustering.cluster.cluster_visualizer Class Reference

Common visualizer of clusters on 1D, 2D or 3D surface. More...

Public Member Functions

def __init__ (self, number_canvases=1, size_row=1, titles=None)
 Constructor of cluster visualizer. More...
 
def append_cluster (self, cluster, data=None, canvas=0, marker='.', markersize=None, color=None)
 Appends cluster to canvas for drawing. More...
 
def append_cluster_attribute (self, index_canvas, index_cluster, data, marker=None, markersize=None)
 Append cluster attribure for cluster on specific canvas. More...
 
def append_clusters (self, clusters, data=None, canvas=0, marker='.', markersize=None)
 Appends list of cluster to canvas for drawing. More...
 
def set_canvas_title (self, text, canvas=0)
 Set title for specified canvas. More...
 
def get_cluster_color (self, index_cluster, index_canvas)
 Returns cluster color on specified canvas.
 
def save (self, filename, kwargs)
 Saves figure to the specified file. More...
 
def show (self, figure=None, invisible_axis=True, visible_grid=True, display=True, shift=None)
 Shows clusters (visualize). More...
 

Detailed Description

Common visualizer of clusters on 1D, 2D or 3D surface.

Use 'cluster_visualizer_multidim' visualizer in case of data dimension is greater than 3.

See also
cluster_visualizer_multidim

Definition at line 390 of file __init__.py.

Constructor & Destructor Documentation

◆ __init__()

def pyclustering.cluster.cluster_visualizer.__init__ (   self,
  number_canvases = 1,
  size_row = 1,
  titles = None 
)

Constructor of cluster visualizer.

Parameters
[in]number_canvases(uint): Number of canvases that is used for visualization.
[in]size_row(uint): Amount of canvases that can be placed in one row.
[in]titles(list): List of canvas's titles.

Example:

# load 2D data sample
sample_2d = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE1);
# load 3D data sample
sample_3d = read_sample(FCPS_SAMPLES.SAMPLE_HEPTA);
# extract clusters from the first sample using DBSCAN algorithm
dbscan_instance = dbscan(sample_2d, 0.4, 2, False);
dbscan_instance.process();
clusters_sample_2d = dbscan_instance.get_clusters();
# extract clusters from the second sample using DBSCAN algorithm
dbscan_instance = dbscan(sample_3d, 1, 3, True);
dbscan_instance.process();
clusters_sample_3d = dbscan_instance.get_clusters();
# create plot with two canvases where each row contains 2 canvases.
size = 2;
row_size = 2;
visualizer = cluster_visualizer(size, row_size);
# place clustering result of sample_2d to the first canvas
visualizer.append_clusters(clusters_sample_2d, sample_2d, 0, markersize = 5);
# place clustering result of sample_3d to the second canvas
visualizer.append_clusters(clusters_sample_3d, sample_3d, 1, markersize = 30);
# show plot
visualizer.show();

Definition at line 399 of file __init__.py.

Member Function Documentation

◆ append_cluster()

def pyclustering.cluster.cluster_visualizer.append_cluster (   self,
  cluster,
  data = None,
  canvas = 0,
  marker = '.',
  markersize = None,
  color = None 
)

Appends cluster to canvas for drawing.

Parameters
[in]cluster(list): cluster that may consist of indexes of objects from the data or object itself.
[in]data(list): If defines that each element of cluster is considered as a index of object from the data.
[in]canvas(uint): Number of canvas that should be used for displaying cluster.
[in]marker(string): Marker that is used for displaying objects from cluster on the canvas.
[in]markersize(uint): Size of marker.
[in]color(string): Color of marker.
Returns
Returns index of cluster descriptor on the canvas.

Definition at line 455 of file __init__.py.

Referenced by pyclustering.cluster.cluster_visualizer.append_clusters().

◆ append_cluster_attribute()

def pyclustering.cluster.cluster_visualizer.append_cluster_attribute (   self,
  index_canvas,
  index_cluster,
  data,
  marker = None,
  markersize = None 
)

Append cluster attribure for cluster on specific canvas.

Attribute it is data that is visualized for specific cluster using its color, marker and markersize if last two is not specified.

Parameters
[in]index_canvas(uint): Index canvas where cluster is located.
[in]index_cluster(uint): Index cluster whose attribute should be added.
[in]data(list): List of points (data) that represents attribute.
[in]marker(string): Marker that is used for displaying objects from cluster on the canvas.
[in]markersize(uint): Size of marker.

Definition at line 510 of file __init__.py.

◆ append_clusters()

def pyclustering.cluster.cluster_visualizer.append_clusters (   self,
  clusters,
  data = None,
  canvas = 0,
  marker = '.',
  markersize = None 
)

Appends list of cluster to canvas for drawing.

Parameters
[in]clusters(list): List of clusters where each cluster may consist of indexes of objects from the data or object itself.
[in]data(list): If defines that each element of cluster is considered as a index of object from the data.
[in]canvas(uint): Number of canvas that should be used for displaying clusters.
[in]marker(string): Marker that is used for displaying objects from clusters on the canvas.
[in]markersize(uint): Size of marker.

Definition at line 538 of file __init__.py.

◆ save()

def pyclustering.cluster.cluster_visualizer.save (   self,
  filename,
  kwargs 
)

Saves figure to the specified file.

Parameters
[in]filename(string): File where the visualized clusters should be stored.
[in]**kwargsArbitrary keyword arguments (available arguments: 'invisible_axis', 'visible_grid').

Keyword Args:

  • invisible_axis (bool): Defines visibility of axes on each canvas, if True - axes are invisible. By default axis are invisible.
  • visible_grid (bool): Defines visibility of grid on each canvas, if True - grid is displayed. By default grid of each canvas is displayed.

There is an example how to save visualized clusters to the PNG file without showing them on a screen:

from pyclustering.cluster import cluster_visualizer
data = [[1.1], [1.7], [3.7], [5.3], [2.5], [-1.5], [-0.9], [6.3], [6.5], [8.1]]
clusters = [[0, 1, 2, 4, 5, 6], [3, 7, 8, 9]]
visualizer = cluster_visualizer()
visualizer.append_clusters(clusters, data)
visualizer.save("1-dimensional-clustering.png")

Definition at line 577 of file __init__.py.

◆ set_canvas_title()

def pyclustering.cluster.cluster_visualizer.set_canvas_title (   self,
  text,
  canvas = 0 
)

Set title for specified canvas.

Parameters
[in]text(string): Title for canvas.
[in]canvas(uint): Index of canvas where title should be displayed.

Definition at line 554 of file __init__.py.

◆ show()

def pyclustering.cluster.cluster_visualizer.show (   self,
  figure = None,
  invisible_axis = True,
  visible_grid = True,
  display = True,
  shift = None 
)

Shows clusters (visualize).

Parameters
[in]figure(fig): Defines requirement to use specified figure, if None - new figure is created for drawing clusters.
[in]invisible_axis(bool): Defines visibility of axes on each canvas, if True - axes are invisible.
[in]visible_grid(bool): Defines visibility of grid on each canvas, if True - grid is displayed.
[in]display(bool): Defines requirement to display clusters on a stage, if True - clusters are displayed, if False - plt.show() should be called by user."
[in]shift(uint): Force canvas shift value - defines canvas index from which custers should be visualized.
Returns
(fig) Figure where clusters are shown.

Definition at line 615 of file __init__.py.

Referenced by pyclustering.cluster.cluster_visualizer.save().


The documentation for this class was generated from the following file: