read_matrix

plot_gmx_densmap.read_matrix(fname)[source]

Read a 2-dimensional matrix from a text file.

The first column of the text file must contain the x values and the first row the y values (note that this is opposed to the standard matrix convention). The value in the upper left corner will be ignored. The remaining elements of the matrix must contain the z values for each (x,y) pair. The file may contain comment lines starting with ‘#’, which will be ignored.

Parameters:

fname (str) – Name of the data file.

Returns:

  • x (numpy.ndarray) – 1-dimensional array containing the x values.

  • y (numpy.ndarray) – 1-dimensional array containing the y values.

  • z (numpy.ndarray) – 2-dimensional array containing the z values for each (x,y) pair. The input matrix is transposed and reversed vertically before it is returned as z. Vividly speaking, the paper on which the matrix is written is turned by 90 degrees anti-clockwise. This is done to get back to the usual matrix representation, where an array z with shape (nrows, ncolumns) is plotted with the column number as x and the row number as y. The remaining difference to the usual matrix representation is that the original origin of the matrix (the value with index [0,0]) is now at the lower left corner (i.e. it is now at [nrows-1,0]).

Notes

This function was originally designed to read the output file that is produced by the GROMACS tool gmx densmap with the ‘-od’ flag and to prepare the matrix for plotting with matplotlib.axes.Axes.imshow().