perClass Documentation
version 5.4 (7-Dec-2018)

kb34: Adjusting marker and color style of each class

Keywords: marker, color, class list, scatter plot, image view

Published on: 18-feb-2016

perClass version used: 4.7 (15-Dec-2015)

Problem: How to define marker and color style for any class?

Solution: Overview of different techniques from interactive to scripting.

34.1. Introduction ↩

perClass allows user to set and keep marker and color style for each class. This is useful when working on real-world applications, where we typically deal with several major classes of interest in multiple data set objects. Standardizing visual style in scatter plots and image views makes it much simpler and faster to interpret the data and spot important clues. In this document, we explore different ways how a user may set custom marker and color style.

Technically, style information is stored in 'marker' and 'color' properties in the class list (sdlist object). This means, that each class/category in a data set carries the styling information with.

34.2. Marker style in interactive scatter ↩

Markers and line styles can be changed interactively from scatter plot using the Change marker menu or context-sensitive menu (started by right click).

Setting marker styles interactively in a scatter plot (perClass/Matlab)

To preserve the user-adjusted style, save the data set back to Matlab workspace (Scatter/Create data set in workspace command or 's' keystroke). This makes sure that any further operation will use the updated style.

34.3. Color style in interactive image view ↩

Image view (sdimage) allows the user to choose class-specific color in three ways:

Setting class color interactively in an image plot (perClass/Matlab)

The last two options make sense, for example, in clustering or segmentation results where we obtain large number of colorful patches.

Similarly to the scatter plot, saving the data set back to Matlab workspace makes sure the color information is preserved.

34.4. Programmatic definition of markers and colors ↩

The getmarkers and setmarkers commands offer high-level interface. One use-case is, that we wish to change markers of all classes in the data set at once. We may simply provide setmarkers with a cell array containing marker specifications in the order of classes in the class list:

>> load medical
>> sdscatter(a)
ans =
 1

>> a
'medical D/ND' 6400 by 11 sddata, 3 classes: 'disease'(1495) 'no-disease'(4267) 'noise'(638) 

>> getmarkers(a)

ans = 

'b+'    'r*'    'mo'

>> b=setmarkers(a,{'r.','go','c.'})
'medical D/ND' 6400 by 11 sddata, 3 classes: 'disease'(1495) 'no-disease'(4267) 'noise'(638) 

>> sdscatter(b)
ans =
 2

Setting marker styles programatically, visualization in interactive scatter plot (perClass/Matlab)

The original style is shown in the left Figure, the new one in the right one. Because we updated the style in the data set, any subset will carry this information with.

Second common use-case is to change marker for one specific class. This is possible simply by providing a name and style string:

>> c=setmarkers(b,'noise','k.')
'medical D/ND' 6400 by 11 sddata, 3 classes: 'disease'(1495) 'no-disease'(4267) 'noise'(638) 
>> sdscatter(c)

ans =

 3

Setting marker style for one specific class

We can change the color for all classes with setcolors command. We provide a cell array with 1x3 vector with R,G and B values.

>> b=setcolors(a,{[1 0 0],[0 1 0],[0.8 0.8 1]})
'medical D/ND' 6400 by 11 sddata, 3 classes: 'disease'(1495) 'no-disease'(4267) 'noise'(638) 

The color is used to visualize classifier decisions in the scatter plot backdrop or in the image visualization, if the data set contains image data.

Any classifier, trained on the data set b, will use the colors we specified:

>> p=sdfisher(b)
sequential pipeline       11x1 'Fisher linear discriminant'
 1 LDA                    11x2 
 2 Gaussian model          2x3  single cov.mat.
 3 Normalization           3x3 
 4 Decision                3x1  weighting, 3 classes

>> sdscatter(b,p)

34.5. Changing default marker and color style ↩

Default marker and color style is defined in the default_markers.m function. You may edit it to change the default behaviour.

34.6. Low-level manipulation of markers and colors ↩

We may access the marker and color information by low-level methods accessing corresponding properties stored in label list. The label list in our data set contains the following properties:

>> b
'medical D/ND' 6400 by 11 sddata, 3 classes: 'disease'(1495) 'no-disease'(4267) 'noise'(638) 

>> getproplist( b.lab )

ans = 

'marker'
'color'

Listing the content of 'marker' property:

>> getprop( b.lab,'marker' )

ans = 

'r.'    'go'    'c.'

The 'marker' property for the category (class) 'disease' is:

>> getprop( b.lab,'marker','disease' )

ans =

r.

Setting the property value directly on the label object:

>> b.lab=setprop( b.lab,'marker','disease','k.' )
'medical D/ND' 6400 by 11 sddata, 3 classes: 'disease'(1495) 'no-disease'(4267) 'noise'(638) 

Because we put in a label object (b.lab), we also receive one which is then directly assigned in b.lab field.

The marker of the disease class is now set as requested:

>> getprop(b.lab,'marker')

ans = 

'k.'    'go'    'c.'