1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """The relax library plotting API."""
24
25
26 from lib.errors import RelaxError
27 from lib.plotting import gnuplot
28 from lib.plotting import grace
29 from lib.plotting import text
30
31
32 -def correlation_matrix(format=None, matrix=None, labels=None, file=None, dir=None, force=False):
33 """Plotting API function for representing correlation matrices.
34
35 @keyword format: The specific backend to use.
36 @type format: str
37 @keyword matrix: The correlation matrix. This must be a square matrix.
38 @type matrix: numpy rank-2 array.
39 @keyword labels: The labels for each element of the matrix. The same label is assumed for each [i, i] pair in the matrix.
40 @type labels: list of str
41 @keyword file: The name of the file to create.
42 @type file: str
43 @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.
44 @type dir: str or None
45 """
46
47
48 function = {
49 'gnuplot': gnuplot.correlation_matrix,
50 'text': text.correlation_matrix
51 }
52
53
54 if format not in function:
55 raise RelaxError("The plotting of correlation matrix data using the '%s' format is not supported." % format)
56
57
58 function[format](matrix=matrix, labels=labels, file=file, dir=dir, force=force)
59
60
61 -def write_xy_data(format=None, data=None, file=None, graph_type=None, norm_type='first', norm=None, autoscale=True):
62 """Write the data into a XY-scatter plot.
63
64 The numerical data should be supplied as a 4 dimensional list or array object. The first dimension corresponds to the graphs. The second corresponds the sets of each graph. The third corresponds to the data series (i.e. each data point). The forth is a list of the information about each point, it is a list where the first element is the x value, the second is the y value, the third is the optional dx or dy error (either dx or dy dependent upon the graph_type arg), and the forth is the optional dy error when graph_type is xydxdy (the third position is then dx).
65
66
67 @keyword format: The specific backend to use. The currently support backends are 'grace'.
68 @type format: str
69 @keyword data: The 4D structure of numerical data to graph (see docstring).
70 @type data: list of lists of lists of float
71 @keyword file: The file object to write the data to.
72 @type file: file object
73 @keyword graph_type: The graph type which can be one of xy, xydy, xydx, or xydxdy.
74 @type graph_type: str
75 @keyword norm_type: The point to normalise to 1. This can be 'first' or 'last'.
76 @type norm_type: str
77 @keyword norm: The normalisation flag which if set to True will cause all graphs to be normalised to 1. The first dimension is the graph.
78 @type norm: None or list of bool
79 @keyword autoscale: A flag which if True will cause the each graph to be autoscaled. If you have supplied a world view for the header or the tick spacing, this argument should be set to False to prevent that world view from being overwritten.
80 @type autoscale: bool
81 """
82
83
84 function = {
85 'grace': grace.write_xy_data,
86 }
87
88
89 if format not in function:
90 raise RelaxError("The plotting of XY data using the '%s' format is not supported." % format)
91
92
93 function[format](data=data, file=file, graph_type=graph_type, norm_type=norm_type, norm=norm, autoscale=autoscale)
94
95
97 """Write the header for XY-scatter plots.
98
99 Many of these keyword arguments should be supplied in a [X, Y] list format, where the first element corresponds to the X data, and the second the Y data. Defaults will be used for any non-supplied args (or lists with elements set to None).
100
101
102 @keyword format: The specific backend to use. The currently support backends are 'grace'.
103 @type format: str
104 @keyword file: The file object to write the data to.
105 @type file: file object
106 @keyword paper_size: The paper size, i.e. 'A4'. For the software Grace, if not set this will default to letter size.
107 @type paper_size: str
108 @keyword title: The title of the graph.
109 @type title: None or str
110 @keyword subtitle: The sub-title of the graph.
111 @type subtitle: None or str
112 @keyword world: The plot default zoom. This consists of a list of the X-axis minimum, Y-axis minimum, X-axis maximum, and Y-axis maximum values. Each graph should supply its own world view.
113 @type world: Nor or list of list of numbers
114 @keyword view: List of 4 coordinates defining the graph view port.
115 @type view: None or list of float
116 @keyword graph_num: The total number of graphs.
117 @type graph_num: int
118 @keyword sets: The number of data sets in each graph.
119 @type sets: list of int
120 @keyword set_names: The names associated with each graph data set (Gx.Sy in Grace). For example this can be a list of spin identification strings. The first dimension is the graph, the second is the set.
121 @type set_names: None or list of list of str
122 @keyword set_colours: The colours for each graph data set Gx.Sy. The first dimension is the graph, the second is the set.
123 @type set_colours: None or list of list of int
124 @keyword x_axis_type_zero: The flags specifying if the X-axis should be placed at zero.
125 @type x_axis_type_zero: None or list of lists of bool
126 @keyword y_axis_type_zero: The flags specifying if the Y-axis should be placed at zero.
127 @type y_axis_type_zero: None or list of lists of bool
128 @keyword symbols: The symbol style for each graph data set (Gx.Sy in Grace). The first dimension is the graph, the second is the set.
129 @type symbols: None or list of list of int
130 @keyword symbol_sizes: The symbol size for each graph data set (Gx.Sy in Grace). The first dimension is the graph, the second is the set.
131 @type symbol_sizes: None or list of list of int
132 @keyword symbol_fill: The symbol file style for each graph data set (Gx.Sy in Grace). The first dimension is the graph, the second is the set.
133 @type symbol_fill: None or list of list of int
134 @keyword linestyle: The line style for each graph data set (Gx.Sy in Grace). The first dimension is the graph, the second is the set.
135 @type linestyle: None or list of list of int
136 @keyword linetype: The line type for each graph data set (Gx.Sy in Grace). The first dimension is the graph, the second is the set.
137 @type linetype: None or list of list of int
138 @keyword linewidth: The line width for all elements of each graph data set (Gx.Sy in Grace). The first dimension is the graph, the second is the set.
139 @type linewidth: None or list of float
140 @keyword data_type: The axis data category (in the [X, Y] list format).
141 @type data_type: None or list of list of str
142 @keyword seq_type: The sequence data type (in the [X, Y] list format). This is for molecular sequence specific data and can be one of 'res', 'spin', or 'mixed'.
143 @type seq_type: None or list of list of str
144 @keyword tick_major_spacing: The spacing between major ticks. This is in the [X, Y] list format whereby the first dimension corresponds to the graph number.
145 @type tick_major_spacing: None or list of list of numbers
146 @keyword tick_minor_count: The number of minor ticks between the major ticks. This is in the [X, Y] list format whereby the first dimension corresponds to the graph number.
147 @type tick_minor_count: None or list of list of int
148 @keyword axis_labels: The labels for the axes (in the [X, Y] list format). The first dimension is the graph.
149 @type axis_labels: None or list of list of str
150 @keyword legend: If True, the legend will be visible. The first dimension is the graph.
151 @type legend: list of bool
152 @keyword legend_pos: The position of the legend, e.g. [0.3, 0.8]. The first dimension is the graph.
153 @type legend_pos: None or list of list of float
154 @keyword legend_box_fill_pattern: The legend box fill. If set to 0, it will become transparent.
155 @type legend_box_fill_pattern: int
156 @keyword legend_char_size: The size of the legend box text.
157 @type legend_char_size: float
158 @keyword norm: The normalisation flag which if set to True will cause all graphs to be normalised to 1. The first dimension is the graph.
159 @type norm: list of bool
160 """
161
162
163 function = {
164 'grace': grace.write_xy_header,
165 }
166
167
168 if format not in function:
169 raise RelaxError("The plotting of XY data using the '%s' format is not supported." % format)
170
171
172 function[format](file=file, paper_size=paper_size, title=title, subtitle=subtitle, world=world, view=view, graph_num=graph_num, sets=sets, set_names=set_names, set_colours=set_colours, x_axis_type_zero=x_axis_type_zero, y_axis_type_zero=y_axis_type_zero, symbols=symbols, symbol_sizes=symbol_sizes, symbol_fill=symbol_fill, linestyle=linestyle, linetype=linetype, linewidth=linewidth, data_type=data_type, seq_type=seq_type, axis_labels=axis_labels, tick_major_spacing=tick_major_spacing, tick_minor_count=tick_minor_count, legend=legend, legend_pos=legend_pos, legend_box_fill_pattern=legend_box_fill_pattern, legend_char_size=legend_char_size, norm=norm)
173