annotate SMART/Java/Python/misc/RPlotter.py @ 18:94ab73e8a190

Uploaded
author m-zytnicki
date Mon, 29 Apr 2013 03:20:15 -0400
parents 769e306b7933
children 0ab839023fe4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
1 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
2 # Copyright INRA-URGI 2009-2010
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
3 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
4 # This software is governed by the CeCILL license under French law and
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
5 # abiding by the rules of distribution of free software. You can use,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
6 # modify and/ or redistribute the software under the terms of the CeCILL
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
7 # license as circulated by CEA, CNRS and INRIA at the following URL
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
8 # "http://www.cecill.info".
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
9 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
10 # As a counterpart to the access to the source code and rights to copy,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
11 # modify and redistribute granted by the license, users are provided only
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
12 # with a limited warranty and the software's author, the holder of the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
13 # economic rights, and the successive licensors have only limited
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
14 # liability.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
15 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
16 # In this respect, the user's attention is drawn to the risks associated
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
17 # with loading, using, modifying and/or developing or reproducing the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
18 # software by the user in light of its specific status of free software,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
19 # that may mean that it is complicated to manipulate, and that also
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
20 # therefore means that it is reserved for developers and experienced
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
21 # professionals having in-depth computer knowledge. Users are therefore
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
22 # encouraged to load and test the software's suitability as regards their
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
23 # requirements in conditions enabling the security of their systems and/or
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
24 # data to be ensured and, more generally, to use and operate it in the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
25 # same conditions as regards security.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
26 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
27 # The fact that you are presently reading this means that you have had
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
28 # knowledge of the CeCILL license and that you accept its terms.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
29 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
30
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
31 import os
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
32 import subprocess
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
33 import random
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
34 import math
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
35
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
36 minPositiveValue = 10e-6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
37
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
38 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
39 Plot simple curves in R
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
40 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
41
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
42 class RPlotter(object):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
43 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
44 Plot some curves
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
45 @ivar nbColors: number of different colors
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
46 @type nbColors: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
47 @ivar fileName: name of the file
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
48 @type fileName: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
49 @ivar lines: lines to be plotted
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
50 @type lines: array of dict
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
51 @ivar names: name of the lines
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
52 @type names: array of strings
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
53 @ivar colors: color of the lines
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
54 @type colors: array of strings
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
55 @ivar types: type of the lines (plain or dashed)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
56 @type types: array of strings
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
57 @ivar format: format of the picture
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
58 @type format: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
59 @ivar lineWidth: width of the line in a xy-plot
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
60 @type lineWidth: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
61 @ivar xMin: minimum value taken on the x-axis
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
62 @type xMin: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
63 @ivar xMax: maximum value taken on the x-axis
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
64 @type xMax: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
65 @ivar yMin: minimum value taken on the y-axis
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
66 @type yMin: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
67 @ivar yMax: maximum value taken on the y-axis
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
68 @type yMax: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
69 @ivar minimumX: minimum value allowed on the x-axis
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
70 @type minimumX: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
71 @ivar maximumX: maximum value allowed on the x-axis
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
72 @type maximumX: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
73 @ivar minimumY: minimum value allowed on the y-axis
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
74 @type minimumY: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
75 @ivar maximumY: maximum value allowed on the y-axis
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
76 @type maximumY: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
77 @ivar leftMargin: add some margin in the left part of the plot
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
78 @type leftMargin: float
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
79 @ivar rightMargin: add some margin in the right part of the plot
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
80 @type rightMargin: float
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
81 @ivar downMargin: add some margin at the top of the plot
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
82 @type downMargin: float
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
83 @ivar upMargin: add some margin at the bottom of the plot
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
84 @type upMargin: float
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
85 @ivar logX: use log scale on the x-axis
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
86 @type logX: boolean
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
87 @ivar logY: use log scale on the y-axis
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
88 @type logY: boolean
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
89 @ivar logZ: use log scale on the z-axis (the color)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
90 @type logZ: boolean
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
91 @ival fill: if a value is not given, fill it with given value
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
92 @type fill: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
93 @ival bucket: cluster the data into buckets of given size
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
94 @type bucket: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
95 @ival seed: a random number
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
96 @type seed: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
97 @ival regression: plot a linear regression
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
98 @type regression: boolean
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
99 @ival legend: set the legend
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
100 @type legend: boolean
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
101 @ival legendBySide: set the legend outside of the plot
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
102 @type legendBySde: boolean
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
103 @ival xLabel: label for the x-axis
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
104 @type xLabel: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
105 @ival yLabel: label for the y-axis
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
106 @type yLabel: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
107 @ival title: title of the plot
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
108 @type title: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
109 @ival barplot: use a barplot representation instead
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
110 @type barplot: boolean
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
111 @ival points: use a point cloud instead
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
112 @type points: boolean
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
113 @ival heatPoints: use a colored point cloud instead
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
114 @type heatPoints: boolean
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
115 @ival axesLabels: change the names of the axes
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
116 @type axesLabels: vector of 2 int to string dict
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
117 @ival rotateAxesLabels: rotate the axes labels
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
118 @type rotateAxesLabels: dict of 2 boolean
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
119 @ival verbosity: verbosity of the class
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
120 @type verbosity: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
121 @ival keep: keep temporary files
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
122 @type keep: boolean
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
123 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
124
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
125 def __init__(self, fileName, verbosity = 0, keep = False):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
126 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
127 Constructor
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
128 @param fileName: name of the file to produce
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
129 @type fileName: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
130 @param verbosity: verbosity
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
131 @type verbosity: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
132 @param keep: keep temporary files
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
133 @type keep: boolean
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
134 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
135 self.nbColors = 9
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
136 self.fileName = fileName
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
137 self.verbosity = verbosity
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
138 self.keep = keep
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
139 self.format = "png"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
140 self.fill = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
141 self.bucket = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
142 self.lines = []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
143 self.names = []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
144 self.colors = []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
145 self.types = []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
146 self.lineWidth = 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
147 self.xMin = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
148 self.xMax = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
149 self.yMin = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
150 self.yMax = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
151 self.seed = random.randint(0, 10000)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
152 self.minimumX = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
153 self.maximumX = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
154 self.minimumY = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
155 self.maximumY = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
156 self.leftMargin = 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
157 self.rightMargin = 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
158 self.topMargin = 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
159 self.bottomMargin = 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
160 self.logX = False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
161 self.logY = False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
162 self.logZ = False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
163 self.regression = False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
164 self.width = 1000
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
165 self.height = 500
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
166 self.legend = False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
167 self.legendBySide = False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
168 self.xLabel = ""
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
169 self.yLabel = ""
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
170 self.title = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
171 self.points = False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
172 self.heatPoints = False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
173 self.barplot = False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
174 self.axesLabels = {1: None, 2: None}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
175 self.rotateAxesLabels = {1: False, 2: False}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
176 self.linesToAddBox = ""
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
177
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
178 def __del__(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
179 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
180 Destructor
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
181 Remove tmp files
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
182 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
183 if not self.keep:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
184 scriptFileName = "tmpScript-%d.R" % (self.seed)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
185 if os.path.exists(scriptFileName):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
186 os.remove(scriptFileName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
187 outputFileName = "%sout" % (scriptFileName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
188 if os.path.exists(outputFileName):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
189 os.remove(outputFileName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
190 nbLines = len(self.lines) + (1 if self.heatPoints else 0)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
191 for i in range(nbLines):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
192 if os.path.exists("tmpData-%d-%d.dat" % (self.seed, i)):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
193 os.remove("tmpData-%d-%d.dat" % (self.seed, i))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
194
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
195
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
196 def setMinimumX(self, xMin):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
197 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
198 Set the minimum value on the x-axis
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
199 @param xMin:minimum value on the x-axis
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
200 @type xMin: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
201 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
202 self.minimumX = xMin
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
203
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
204
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
205 def setMaximumX(self, xMax):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
206 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
207 Set the maximum value on the x-axis
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
208 @param xMax: maximum value on the x-axis
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
209 @type xMax: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
210 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
211 self.maximumX = xMax
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
212
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
213
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
214 def setMinimumY(self, yMin):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
215 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
216 Set the minimum value on the y-axis
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
217 @param yMin: minimum value on the y-axis
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
218 @type yMin: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
219 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
220 self.minimumY = yMin
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
221
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
222
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
223 def setMaximumY(self, yMax):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
224 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
225 Set the maximum value on the y-axis
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
226 @param yMax: maximum value on the y-axis
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
227 @type xmax: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
228 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
229 self.maximumY = yMax
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
230
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
231
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
232 def setFill(self, fill):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
233 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
234 Fill empty data with given value
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
235 @param fill: the value to fill with
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
236 @type fill: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
237 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
238 self.fill = fill
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
239
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
240
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
241 def setBuckets(self, bucket):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
242 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
243 Cluster the data into buckets of given size
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
244 @param bucket: the size of the buckets
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
245 @type bucket: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
246 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
247 self.bucket = bucket
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
248
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
249
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
250 def setRegression(self, regression):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
251 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
252 Plot a linear regression line
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
253 @param regression: whether to plot the regression
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
254 @type regression: bool
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
255 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
256 self.regression = regression
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
257
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
258
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
259 def setFormat(self, format):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
260 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
261 Set the format of the picture
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
262 @param format: the format
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
263 @type format: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
264 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
265 if format not in ("png", "pdf", "jpeg", "bmp", "tiff"):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
266 raise Exception("Format '%s' is not supported by RPlotter" % (format))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
267 self.format = format
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
268
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
269
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
270 def setWidth(self, width):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
271 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
272 Set the dimensions of the image produced
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
273 @param width: width of the image
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
274 @type width: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
275 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
276 self.width = width
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
277
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
278
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
279 def setHeight(self, height):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
280 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
281 Set the dimensions of the image produced
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
282 @param height: heigth of the image
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
283 @type height: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
284 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
285 self.height = height
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
286
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
287
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
288 def setImageSize(self, width, height):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
289 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
290 Set the dimensions of the image produced
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
291 @param width: width of the image
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
292 @type width: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
293 @param height: heigth of the image
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
294 @type height: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
295 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
296 self.setWidth(width)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
297 self.setHeight(height)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
298
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
299
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
300 def setLegend(self, legend, bySide = False):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
301 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
302 Print a legend or not
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
303 @param legend: print a legend
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
304 @type legend: boolean
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
305 @param bySide: put the legend outside of the plot
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
306 @type bySide: boolean
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
307 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
308 self.legend = legend
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
309 self.legendBySide = bySide
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
310
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
311
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
312 def setXLabel(self, label):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
313 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
314 Print a label for the x-axis
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
315 @param label: the label
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
316 @type label: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
317 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
318 self.xLabel = label
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
319 if self.xLabel != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
320 self.xLabel = self.xLabel.replace("_", " ")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
321
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
322
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
323 def setYLabel(self, label):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
324 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
325 Print a label for the y-axis
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
326 @param label: the label
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
327 @type label: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
328 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
329 self.yLabel = label
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
330 if self.yLabel != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
331 self.yLabel = self.yLabel.replace("_", " ")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
332
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
333
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
334 def addLeftMargin(self, margin):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
335 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
336 Increase the size of the space on the left part of the graph
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
337 @param margin: the space added
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
338 @type margin: float
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
339 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
340 self.leftMargin = margin
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
341
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
342
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
343 def addRightMargin(self, margin):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
344 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
345 Increase the size of the space on the right part of the graph
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
346 @param margin: the space added
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
347 @type margin: float
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
348 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
349 self.rightMargin = margin
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
350
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
351
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
352 def addTopMargin(self, margin):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
353 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
354 Increase the size of the space at the top of the graph
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
355 TopMargin is a percentage if 0 < TopMargin < 1.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
356 TopMargin is a value if TopMargin >= 1.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
357 @param margin: the space added
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
358 @type margin: float
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
359 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
360 self.topMargin = margin
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
361
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
362
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
363 def addBottomMargin(self, margin):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
364 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
365 Increase the size of the space at the bottom of the graph
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
366 @param margin: the space added
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
367 @type margin: float
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
368 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
369 self.bottomMargin = margin
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
370
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
371
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
372 def getNewYMaxWithTopMargin(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
373 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
374 Return new xMin coordinate with left margin
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
375 @param xMin: coordinate
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
376 @type xMin: float
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
377 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
378 yMax = self.yMax
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
379 if 0 < self.topMargin and self.topMargin < 1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
380 topMargin = self.topMargin * self.yMax
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
381 yMax = self.yMax + topMargin
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
382 elif self.topMargin >= 1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
383 yMax = self.yMax + self.topMargin
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
384 return yMax
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
385
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
386
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
387 def setTitle(self, title):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
388 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
389 Print a title for graph
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
390 @param title: a title
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
391 @type title: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
392 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
393 self.title = title
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
394 if self.title != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
395 self.title = self.title.replace("_", " ")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
396
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
397
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
398 def setAxisLabel(self, i, labels):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
399 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
400 Change x- or y-labels
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
401 @param i: x for x-label, y for y-label
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
402 @type i: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
403 @param labels: new labels
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
404 @type labels: int to string dict
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
405 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
406 i = i.lower()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
407 if i not in ("x", "y"):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
408 raise Exception("Label name '" + i + "' should by 'x' or 'y' while changing axis labels.")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
409 self.axesLabels[{"x": 1, "y": 2}[i]] = labels
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
410
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
411
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
412 def rotateAxisLabel(self, i, b = True):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
413 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
414 Rotate x- or y-labels
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
415 @param i: x for x-label, y for y-label
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
416 @type i: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
417 @param b: whether the labels should be rotated
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
418 @type b: boolean
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
419 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
420 i = i.lower()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
421 if i not in ("x", "y"):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
422 raise Exception("Label name '" + i + "' should by 'x' or 'y' while rotating axis labels.")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
423 self.rotateAxesLabels[{"x": 1, "y": 2}[i]] = b
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
424
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
425 def setLineWidth(self, width):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
426 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
427 Set the line width in a xy-plot
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
428 @param width: the new line width
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
429 @type width: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
430 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
431 self.lineWidth = width
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
432
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
433 def setLog(self, log):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
434 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
435 Use log-scale for axes
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
436 @param log: use log scale
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
437 @type log: boolean
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
438 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
439 self.logX = ("x" in log)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
440 self.logY = ("y" in log)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
441 self.logZ = ("z" in log)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
442
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
443
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
444 def setBarplot(self, barplot):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
445 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
446 Use barplot representation instead
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
447 @param barplot: barplot representation
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
448 @type barplot: boolean
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
449 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
450 self.barplot = barplot
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
451
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
452
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
453 def setPoints(self, points):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
454 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
455 Use points cloud representation instead
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
456 @param points: points cloud representation
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
457 @type points: boolean
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
458 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
459 self.points = points
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
460
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
461
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
462 def setHeatPoints(self, heatPoints):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
463 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
464 Use points cloud representation with color representing another variable instead
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
465 @param points: colored points cloud representation
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
466 @type points: boolean
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
467 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
468 self.heatPoints = heatPoints
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
469
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
470
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
471 def addBox(self, lXCoordList, minY, maxY):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
472 for lXCoord in lXCoordList:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
473 self.linesToAddBox += "rect(%s,%s,%s,%s,density=50, col='grey',border='transparent')\n" % (lXCoord[0], minY, lXCoord[1], maxY)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
474
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
475 def addLine(self, line, name = "", color = None):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
476 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
477 Add a line
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
478 @param line: a line to plot
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
479 @type line: dict
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
480 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
481 # prepare data
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
482 plot = []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
483 if self.points or self.heatPoints:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
484 values = line.values()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
485 elif self.fill == None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
486 values = sorted(line.keys())
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
487 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
488 values = range(min(line.keys()), max(line.keys()) + 1)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
489
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
490 for element in values:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
491 if self.points or self.heatPoints:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
492 x = element[0]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
493 y = element[1]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
494 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
495 x = element
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
496 if x not in line:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
497 y = self.fill
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
498 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
499 y = line[x]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
500
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
501 if self.minimumX != None and x < self.minimumX:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
502 continue
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
503 if self.maximumX != None and x > self.maximumX:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
504 continue
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
505
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
506 if x == None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
507 raise Exception("Problem! x is None. Aborting...")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
508 if y == None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
509 raise Exception("Problem! y is None. Aborting...")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
510 if x == 0 and self.logX:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
511 x = minPositiveValue
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
512 if y == 0 and self.logY:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
513 y = minPositiveValue
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
514 if self.xMin == None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
515 if not self.logX or x != 0:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
516 self.xMin = x
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
517 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
518 if not self.logX or x != 0:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
519 self.xMin = min(self.xMin, x)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
520 if self.xMax == None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
521 self.xMax = x
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
522 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
523 self.xMax = max(self.xMax, x)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
524 if self.yMin == None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
525 if not self.logY or y != 0:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
526 self.yMin = y
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
527 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
528 if not self.logY or y != 0:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
529 if y != "NA":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
530 self.yMin = min(self.yMin, y)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
531 if self.yMax == None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
532 self.yMax = y
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
533 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
534 if y != "NA":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
535 self.yMax = max(self.yMax, y)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
536
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
537 plot.append((x, y))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
538
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
539 # cluster the data into buckets
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
540 if self.bucket != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
541 buckets = dict([((int(value) / int(self.bucket)) * self.bucket, 0) for value in xrange(min(line.keys()), max(line.keys())+1)])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
542 for distance, nb in line.iteritems():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
543 buckets[(int(distance) / int(self.bucket)) * self.bucket] += nb
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
544 self.yMax = max(buckets.values())
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
545 plot = []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
546 for x, y in buckets.iteritems():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
547 plot.append((x, y))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
548
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
549 # write file
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
550 dataFileName = "tmpData-%d-%d.dat" % (self.seed, len(self.lines))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
551 dataHandle = open(dataFileName, "w")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
552 if not self.heatPoints:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
553 plot.sort()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
554 for (x, y) in plot:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
555 if y != "NA":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
556 dataHandle.write("%f\t%f\n" % (x, y))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
557 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
558 dataHandle.write("%f\t%s\n" % (x, y))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
559 dataHandle.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
560
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
561 self.lines.append(line)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
562 self.names.append(name)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
563
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
564 if color == None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
565 colorNumber = len(self.colors) % (self.nbColors - 1) + 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
566 type = "solid"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
567 if len(self.colors) >= self.nbColors:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
568 type = "dashed"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
569 color = "colorPanel[%d]" % (colorNumber)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
570 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
571 color = "\"%s\"" % (color)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
572 type = "solid"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
573 self.colors.append(color)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
574 self.types.append(type)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
575
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
576
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
577 def addHeatLine(self, line, name = "", color = None):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
578 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
579 Add the heat line
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
580 @param line: the line which gives the color of the points
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
581 @type line: dict
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
582 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
583 if not self.heatPoints:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
584 raise Exception("Error! Trying to add a heat point whereas not mentioned to earlier! Aborting.")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
585
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
586 dataFileName = "tmpData-%d-%d.dat" % (self.seed, len(self.lines))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
587 dataHandle = open(dataFileName, "w")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
588
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
589 minimumHeat = min(line.values())
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
590 maximumHeat = max(line.values())
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
591 minLogValue = 0.00001
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
592 log = self.logZ
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
593
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
594 if log:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
595 if minimumHeat == 0:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
596 for element in line:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
597 line[element] += minLogValue
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
598 minimumHeat += minLogValue
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
599 maximumHeat += minLogValue
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
600 minimumHeat = math.log10(minimumHeat)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
601 maximumHeat = math.log10(maximumHeat)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
602
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
603 coeff = 255.0 / (maximumHeat - minimumHeat)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
604
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
605 for element in line:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
606 value = line[element]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
607 if log:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
608 value = math.log10(max(minLogValue, value))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
609 dataHandle.write("\"#%02X%02X00\"\n" % (int((value - minimumHeat) * coeff), 255 - int((value - minimumHeat) * coeff)))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
610
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
611 dataHandle.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
612 self.names.append(name)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
613 if color == None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
614 colorNumber = len(self.colors) % (self.nbColors - 1) + 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
615 type = "solid"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
616 if len(self.colors) >= self.nbColors:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
617 type = "dashed"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
618 color = "colorPanel[%d]" % (colorNumber)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
619 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
620 color = "\"%s\"" % (color)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
621 type = "solid"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
622 self.colors.append(color)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
623 self.types.append(type)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
624
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
625
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
626 def getScript(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
627 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
628 Write (unfinished) R script
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
629 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
630 script = ""
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
631
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
632 xMin = self.xMin - self.leftMargin
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
633 if self.minimumX != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
634 xMin = max(xMin, self.minimumX)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
635 xMax = self.xMax + self.rightMargin
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
636 if self.maximumX != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
637 xMax = min(xMax, self.maximumX)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
638 yMin = self.yMin - self.bottomMargin
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
639 if self.minimumY != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
640 yMin = self.minimumY
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
641 yMax = self.getNewYMaxWithTopMargin()
18
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
642 yMax += min(1, yMax / 100.0)
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
643 if self.maximumY != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
644 yMax = self.maximumY
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
645
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
646 log = ""
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
647 if self.logX:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
648 log += "x"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
649 if self.logY:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
650 log += "y"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
651 if log != "":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
652 log = ", log=\"%s\"" % (log)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
653
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
654 title = ""
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
655 if self.title != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
656 title = ", main = \"%s\"" % (self.title)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
657
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
658 if self.legend and self.legendBySide:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
659 script += "layout(matrix(c(1,2), 1, 2), widths=c(5,1))\n"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
660
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
661 if self.rotateAxesLabels[2]:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
662 script += "par(mar=c(5,12,4,2))\n"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
663 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
664 script += "par(mar=c(5,5,4,2))\n"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
665
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
666 addAxes = True
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
667
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
668 if self.barplot:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
669 script += "data = scan(\"tmpData-%d-0.dat\", list(x = -666, y = -666))\n" % (self.seed)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
670 if len(self.lines) == 1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
671 script += "barplot(data$y, name = data$x, xlab=\"%s\", ylab=\"%s\", ylim = c(%f, %f), cex.axis = 2, cex.names = 2, cex.lab = 2%s%s)\n" % (self.xLabel, self.yLabel, yMin, yMax, title, log)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
672 addAxes = False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
673 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
674 script += "data1 = scan(\"tmpData-%d-1.dat\", list(x = -666, y = -666))\n" % (self.seed)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
675 script += "barplot(rbind(data$y, data1$y), name = data$x, xlab=\"%s\", ylab=\"%s\", cex.axis = 2, cex.names = 2, cex.lab = 2%s, beside = TRUE, space=c(-1,0), axes = FALSE%s)\n" % (self.xLabel, self.yLabel, title, log)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
676 elif self.points:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
677 script += "data = scan(\"tmpData-%d-0.dat\", list(x = -666, y = -666))\n" % (self.seed)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
678 script += "plot(data$x, data$y, xlab=\"%s\", ylab=\"%s\", cex.axis = 2, cex.lab = 2, axes = FALSE%s%s)\n" % (self.xLabel, self.yLabel, title, log)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
679 if self.regression:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
680 x = "log10(data$x)" if self.logX else "data$x"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
681 y = "log10(data$y)" if self.logY else "data$y"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
682 script += "abline(lm(%s ~ %s))\n" % (y, x)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
683 elif self.heatPoints:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
684 if len(self.lines) != 1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
685 raise Exception("Error! Bad number of input data! Aborting...")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
686 script += "data = scan(\"tmpData-%d-0.dat\", list(x = -666, y = -666))\n" % (self.seed)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
687 script += "heatData = scan(\"tmpData-%d-1.dat\", list(x = \"\"))\n" % (self.seed)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
688 script += "plot(data$x, data$y, col=heatData$x, xlab=\"%s\", ylab=\"%s\", cex.axis = 2, cex.lab = 2, axes = FALSE%s%s)\n" % (self.xLabel, self.yLabel, title, log)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
689 if self.regression:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
690 x = "log10(data$x)" if self.logX else "data$x"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
691 y = "log10(data$y)" if self.logY else "data$y"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
692 script += "abline(lm(%s ~ %s))\n" % (y, x)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
693 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
694 script += "plot(x = NA, y = NA, panel.first = grid(lwd = 1.0), xlab=\"%s\", ylab=\"%s\", xlim = c(%f, %f), ylim = c(%f, %f), cex.axis = 2, cex.lab = 2, axes = FALSE%s%s)\n" % (self.xLabel, self.yLabel, xMin, xMax, yMin, yMax, title, log)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
695 for i in range(0, len(self.lines)):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
696 script += "data = scan(\"tmpData-%d-%d.dat\", list(x = -666.666, y = -666.666))\n" % (self.seed, i)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
697 script += "lines(x = data$x, y = data$y, col = %s, lty = \"%s\", lwd = %d)\n" % (self.colors[i], self.types[i], self.lineWidth)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
698
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
699 script += self.linesToAddBox
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
700
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
701 if addAxes:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
702 for i in self.axesLabels:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
703 rotation = ", las = 2" if self.rotateAxesLabels[i] else ""
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
704 if self.axesLabels[i] == None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
705 script += "axis(%d, cex.axis = 2, cex.lab = 2%s)\n" % (i, rotation)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
706 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
707 oldKeys = ", ".join(["%d" % (key) for key in sorted(self.axesLabels[i].keys())])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
708 newKeys = ", ".join(["\"%s\"" % (self.axesLabels[i][key]) for key in sorted(self.axesLabels[i].keys())])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
709 script += "axis(%d, at=c(%s), lab=c(%s), cex.axis = 2, cex.lab = 2%s)\n" % (i, oldKeys, newKeys, rotation)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
710 script += "box()\n"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
711
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
712 if self.legend:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
713 if self.legendBySide:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
714 script += "plot.new()\n"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
715 script += "par(mar=c(0,0,0,0))\n"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
716 script += "plot.window(c(0,1), c(0,1))\n"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
717 script += "legends = c(%s)\n" % ", ".join(["\"%s\"" % name for name in self.names])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
718 script += "colors = c(%s)\n" % ", ".join(["%s" % color for color in self.colors])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
719 script += "lineTypes = c(%s)\n" % ", ".join(["\"%s\"" % type for type in self.types])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
720 if self.legendBySide:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
721 script += "legend(0, 1, legend = legends, xjust = 0, yjust = 1, col = colors, lty = lineTypes, lwd = %d, cex = 1.5, ncol = 1, bg = \"white\")\n" % (self.lineWidth)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
722 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
723 script += "legend(\"topright\", legend = legends, xjust = 0, yjust = 1, col = colors, lty = lineTypes, lwd = %d, cex = 1.5, ncol = 1, bg = \"white\")\n" % (self.lineWidth)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
724
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
725 return script
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
726
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
727
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
728
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
729 def plot(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
730 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
731 Plot the lines
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
732 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
733 scriptFileName = "tmpScript-%d.R" % (self.seed)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
734 scriptHandle = open(scriptFileName, "w")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
735 scriptHandle.write("library(RColorBrewer)\n")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
736 scriptHandle.write("colorPanel = brewer.pal(n=%d, name=\"Set1\")\n" % (self.nbColors))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
737 scriptHandle.write("%s(%s = \"%s\", width = %d, height = %d, bg = \"white\")\n" % (self.format, "filename" if self.format != "pdf" else "file", self.fileName, self.width, self.height))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
738 scriptHandle.write(self.getScript())
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
739 scriptHandle.write("dev.off()\n")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
740 scriptHandle.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
741 rCommand = "R"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
742 if "SMARTRPATH" in os.environ:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
743 rCommand = os.environ["SMARTRPATH"]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
744 command = "\"%s\" CMD BATCH %s" % (rCommand, scriptFileName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
745 status = subprocess.call(command, shell=True)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
746
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
747 if status != 0:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
748 self.keep = True
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
749 raise Exception("Problem with the execution of script file %s, status is: %s" % (scriptFileName, status))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
750
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
751
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
752 def getCorrelationData(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
753 if not self.regression:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
754 return ""
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
755 scriptFileName = "tmpScript-%d.R" % (self.seed)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
756 rScript = open(scriptFileName, "w")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
757 rScript.write("data = scan(\"tmpData-%d-0.dat\", list(x = -0.000000, y = -0.000000))\n" % (self.seed))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
758 x = "log10(data$x)" if self.logX else "data$x"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
759 y = "log10(data$y)" if self.logY else "data$y"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
760 rScript.write("summary(lm(%s ~ %s))\n" % (y, x))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
761 rScript.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
762 rCommand = "R"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
763 if "SMARTRPATH" in os.environ:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
764 rCommand = os.environ["SMARTRPATH"]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
765 command = "\"%s\" CMD BATCH %s" % (rCommand, scriptFileName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
766 status = subprocess.call(command, shell=True)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
767 if status != 0:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
768 self.keep = True
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
769 raise Exception("Problem with the execution of script file %s computing the correlation, status is: %s" % (scriptFileName, status))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
770 outputRFile = open("%sout" % (scriptFileName))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
771 output = ""
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
772 start = False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
773 end = False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
774 for line in outputRFile:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
775 if start and "> " in line:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
776 end = True
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
777 if start and not end:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
778 output += line
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
779 if "summary" in line:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
780 start = True
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
781 return output
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
782
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
783
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
784 def getSpearmanRho(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
785 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
786 Get the Spearman rho correlation using R
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
787 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
788 return None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
789 if not self.points and not self.barplot and not self.heatPoints:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
790 raise Exception("Cannot compute Spearman rho correlation whereas not in 'points' or 'bar' mode.")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
791
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
792 scriptFileName = "tmpScript-%d.R" % (self.seed)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
793 rScript = open(scriptFileName, "w")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
794 rScript.write("library(Hmisc)\n")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
795 rScript.write("data = scan(\"tmpData-%d-0.dat\", list(x = -0.000000, y = -0.000000))\n" % (self.seed))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
796 rScript.write("spearman(data$x, data$y)\n")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
797 rScript.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
798
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
799 rCommand = "R"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
800 if "SMARTRPATH" in os.environ:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
801 rCommand = os.environ["SMARTRPATH"]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
802 command = "\"%s\" CMD BATCH %s" % (rCommand, scriptFileName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
803 status = subprocess.call(command, shell=True)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
804
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
805 if status != 0:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
806 self.keep = True
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
807 raise Exception("Problem with the execution of script file %s, status is: %s" % (scriptFileName, status))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
808
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
809 outputRFile = open("%sout" % (scriptFileName))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
810 nextLine = False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
811 for line in outputRFile:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
812 line = line.strip()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
813 if nextLine:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
814 if line == "NA":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
815 return None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
816 return float(line)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
817 nextLine = False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
818 if line == "rho":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
819 nextLine = True
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
820
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
821 return None