From Christoph's Personal Wiki
Jump to: navigation, search
The correct title of this article is matrix2png. The initial letter is capitalized due to technical restrictions.

matrix2png is a simple but powerful programme for making visualizations of microarray data and many other data types. It generates PNG formatted images from text files of data. It is fast, easy to use, and reasonably flexible. It can be used to generate publication-quality images, or to act as a image generator for web applications. It is useful for imaging all kinds of matrix-based data, not just microarray data. Matrix2png is open source.

The current version of matrix2png is 1.2.2 (February 2012).


see: here for detailed usage and examples.
-data <file> 
-desctext <file> 
values assigned to mincolor and maxcolor as min:max (default is data range)
contrast (default = 1.0; applies only when not using -range option)
pixel dimensions per value as x:y (default = 2:2)
number of colours (default = 64)
minimum image size as x:y pixels
colour used at lowest value (name or r:g:b triplet) (default = blue)
colour used at highest value (name or r:g:b triplet) (default = red)
colour used as background (name or r:g:b triplet) (default = white)
colour used for missing values (name or r:g:b triplet) (default = grey)
colour choices from preset maps: overrides min/max colours and -b (default = 0 (none))
Use discretized mapping of values to colors; use -dmap to assign a mapping file
-dmap <mapping file> 
Discrete colour mapping file to use for discrete mapping (default = preset)
Number of rows to process starting from the top of the matrix by default
Number of columns to process starting from the left edge of the matrix by default
Index of the first row to be processed; can combine with numr (default=1)
Index of the first column to be processed; can combine with numc (default=1)
Trim this percent of data extremes when determining data range (only without the -range option)
Verbosity of the output 1|2|3|4|5 (default=2)
-title <title> 
Add a title
Row-normalize the data to mean 0 and variance 1
Middle of colour range is black
Add cell dividers
Add scale bar
Add row names
Add column names
Data file has a format line
Draw ellipses instead of rectangles
Log transform the data (base 2)


If, for an example, you have a matrix file ('foo.mat') that has something like the following matrix:

foo A1 A2 A3
B1   4  3  9
B2   3  2  1
B3   7  5  8

Note: All entries must be tab delimited.

You can convert this to a PNG like so:

matrix2png -data foo.mat -size 18:18 -mincolor darkred -maxcolor white -c -r -s -con 1.0 >foo.png

Example with Gnuplot

Note: There should be no field names in the rows or columns.

set palette rgbformula 7,-2,7
p 'foo.mat' matrix u 1:(-$2):3 w image


-mincolor <value> 
(ignored if using "-map"), -maxcolor (ignored if using "-map"), -bkgcolor: The colors which are used for the image scale. The smallest value in the image (or values less than or equal to the minvalue) are represented by mincolor, same idea for maxcolor. The background color is used for areas of the image not covered by the matrix data - which means that you may not see the background color at all. Colors can be selected by name or by red:green:blue triplets (values ranging from 0 to 255). Thus pure red is indicated by 255:0:0 while medium grey would be 128:128:128. Colors which can be selected by name are:
red, darkred, blue, darkblue, green, darkgreen, yellow, magenta, cyan, black, white, grey (or gray), orange, violet
Other colors are generated by interpolating between the min and max colors; by using color maps (below), you can use preset mappings that are more complex. (Defaults: mincolor=blue; maxcolor=red; bkgcolor=white.)


  • Pavlidis P, Noble WS (2003). "Matrix2png: A Utility for Visualizing Matrix Data". Bioinformatics 19:295-296.

External links