Package lib :: Package plotting :: Module text
[hide private]
[frames] | no frames]

Source Code for Module lib.plotting.text

 1  ############################################################################### 
 2  #                                                                             # 
 3  # Copyright (C) 2014 Edward d'Auvergne                                        # 
 4  #                                                                             # 
 5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
 6  #                                                                             # 
 7  # This program is free software: you can redistribute it and/or modify        # 
 8  # it under the terms of the GNU General Public License as published by        # 
 9  # the Free Software Foundation, either version 3 of the License, or           # 
10  # (at your option) any later version.                                         # 
11  #                                                                             # 
12  # This program is distributed in the hope that it will be useful,             # 
13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
15  # GNU General Public License for more details.                                # 
16  #                                                                             # 
17  # You should have received a copy of the GNU General Public License           # 
18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
19  #                                                                             # 
20  ############################################################################### 
21   
22  # Module docstring. 
23  """Module for data plotting in plain text format.""" 
24   
25  # relax module imports. 
26  from lib.io import open_write_file 
27   
28   
29 -def correlation_matrix(matrix=None, labels=None, file=None, dir=None, force=False):
30 """Gnuplot plotting function for representing correlation matrices. 31 32 @keyword matrix: The correlation matrix. This must be a square matrix. 33 @type matrix: numpy rank-2 array. 34 @keyword labels: The labels for each element of the matrix. The same label is assumed for each [i, i] pair in the matrix. 35 @type labels: list of str 36 @keyword file: The name of the file to create. 37 @type file: str 38 @keyword dir: The directory where the PDB file will be placed. If set to None, then the file will be placed in the current directory. 39 @type dir: str or None 40 """ 41 42 # Open the text file for writing. 43 output = open_write_file(file, dir=dir, force=force) 44 45 # The dimensions. 46 n = len(matrix) 47 48 # The header line. 49 output.write('#') 50 for i in range(n): 51 if i == 0: 52 output.write(" %18s" % labels[i]) 53 else: 54 output.write(" %20s" % labels[i]) 55 output.write('\n') 56 57 # Output the matrix. 58 for i in range(n): 59 for j in range(n): 60 # Output the matrix. 61 if j == 0: 62 output.write("%20.15f" % matrix[i, j]) 63 else: 64 output.write(" %20.15f" % matrix[i, j]) 65 66 # End of the current line. 67 output.write('\n') 68 69 # Close the file. 70 output.close()
71