##// END OF EJS Templates
Daniel Valdez -
r279:198e40210b2c
parent child
Show More
@@ -1,373 +1,373
1 1 import numpy
2 2 import datetime
3 3 import sys
4 4 import matplotlib
5 5
6 6 if 'linux' in sys.platform:
7 7 matplotlib.use("TKAgg")
8 8
9 9 if 'darwin' in sys.platform:
10 10 matplotlib.use("TKAgg")
11 11
12 12 import matplotlib.pyplot
13 13
14 14 from mpl_toolkits.axes_grid1 import make_axes_locatable
15 15 from matplotlib.ticker import *
16 16
17 17 ###########################################
18 18 #Actualizacion de las funciones del driver
19 19 ###########################################
20 20
21 21 def createFigure(idfigure, wintitle, width, height, facecolor="w"):
22 22
23 23 matplotlib.pyplot.ioff()
24 24 fig = matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor)
25 25 fig.canvas.manager.set_window_title(wintitle)
26 26 fig.canvas.manager.resize(width, height)
27 27 matplotlib.pyplot.ion()
28 28 matplotlib.pyplot.show()
29 29
30 30 return fig
31 31
32 32 def closeFigure():
33 33
34 34 matplotlib.pyplot.ioff()
35 35 matplotlib.pyplot.show()
36 36
37 37 return
38 38
39 39 def saveFigure(fig, filename):
40 40
41 41 matplotlib.pyplot.ioff()
42 42 fig.savefig(filename)
43 43 matplotlib.pyplot.ion()
44 44
45 45 def setWinTitle(fig, title):
46 46
47 47 fig.canvas.manager.set_window_title(title)
48 48
49 49 def setTitle(fig, title):
50 50
51 51 fig.suptitle(title)
52 52
53 53 def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan):
54 54
55 55 matplotlib.pyplot.ioff()
56 56 matplotlib.pyplot.figure(fig.number)
57 57 axes = matplotlib.pyplot.subplot2grid((nrow, ncol),
58 58 (xpos, ypos),
59 59 colspan=colspan,
60 60 rowspan=rowspan)
61 61
62 62 matplotlib.pyplot.ion()
63 63 return axes
64 64
65 65 def setAxesText(ax, text):
66 66
67 67 ax.annotate(text,
68 68 xy = (.1, .99),
69 69 xycoords = 'figure fraction',
70 70 horizontalalignment = 'left',
71 71 verticalalignment = 'top',
72 72 fontsize = 10)
73 73
74 74 def printLabels(ax, xlabel, ylabel, title):
75 75
76 76 ax.set_xlabel(xlabel, size=11)
77 77 ax.set_ylabel(ylabel, size=11)
78 78 ax.set_title(title, size=12)
79 79
80 80 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='',
81 81 ticksize=9, xtick_visible=True, ytick_visible=True,
82 82 nxticks=4, nyticks=10,
83 83 grid=None):
84 84
85 85 """
86 86
87 87 Input:
88 88 grid : None, 'both', 'x', 'y'
89 89 """
90 90
91 91 matplotlib.pyplot.ioff()
92 92
93 93 ax.set_xlim([xmin,xmax])
94 94 ax.set_ylim([ymin,ymax])
95 95
96 96 printLabels(ax, xlabel, ylabel, title)
97 97
98 98 ######################################################
99 99 if (xmax-xmin)<=1:
100 100 xtickspos = numpy.linspace(xmin,xmax,nxticks)
101 101 xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos])
102 102 ax.set_xticks(xtickspos)
103 103 else:
104 104 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
105 105 ax.set_xticks(xtickspos)
106 106
107 107 for tick in ax.get_xticklabels():
108 108 tick.set_visible(xtick_visible)
109 109
110 110 for tick in ax.xaxis.get_major_ticks():
111 111 tick.label.set_fontsize(ticksize)
112 112
113 113 ######################################################
114 114 for tick in ax.get_yticklabels():
115 115 tick.set_visible(ytick_visible)
116 116
117 117 for tick in ax.yaxis.get_major_ticks():
118 118 tick.label.set_fontsize(ticksize)
119 119
120 120 ax.plot(x, y)
121 121 iplot = ax.lines[-1]
122 122
123 123 ######################################################
124 124 if '0.' in matplotlib.__version__[0:2]:
125 125 print "The matplotlib version has to be updated to 1.1 or newer"
126 126 return iplot
127 127
128 128 if '1.0.' in matplotlib.__version__[0:4]:
129 129 print "The matplotlib version has to be updated to 1.1 or newer"
130 130 return iplot
131 131
132 132 if grid != None:
133 133 ax.grid(b=True, which='major', axis=grid)
134 134
135 135 matplotlib.pyplot.tight_layout()
136 136
137 137 matplotlib.pyplot.ion()
138 138
139 139 return iplot
140 140
141 141 def set_linedata(ax, x, y, idline):
142 142
143 143 ax.lines[idline].set_data(x,y)
144 144
145 145 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
146 146
147 147 ax = iplot.get_axes()
148 148
149 149 printLabels(ax, xlabel, ylabel, title)
150 150
151 151 set_linedata(ax, x, y, idline=0)
152 152
153 153 def addpline(ax, x, y, color, linestyle, lw):
154 154
155 155 ax.plot(x,y,color=color,linestyle=linestyle,lw=lw)
156 156
157 157
158 158 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
159 159 xlabel='', ylabel='', title='', ticksize = 9,
160 160 colormap='jet',cblabel='', cbsize="5%",
161 161 XAxisAsTime=False):
162 162
163 163 matplotlib.pyplot.ioff()
164 164
165 165 divider = make_axes_locatable(ax)
166 166 ax_cb = divider.new_horizontal(size=cbsize, pad=0.05)
167 167 fig = ax.get_figure()
168 168 fig.add_axes(ax_cb)
169 169
170 170 ax.set_xlim([xmin,xmax])
171 171 ax.set_ylim([ymin,ymax])
172 172
173 173 printLabels(ax, xlabel, ylabel, title)
174 174
175 175 imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap))
176 176 cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
177 177 cb.set_label(cblabel)
178 178
179 179 # for tl in ax_cb.get_yticklabels():
180 180 # tl.set_visible(True)
181 181
182 182 for tick in ax.yaxis.get_major_ticks():
183 183 tick.label.set_fontsize(ticksize)
184 184
185 185 for tick in ax.xaxis.get_major_ticks():
186 186 tick.label.set_fontsize(ticksize)
187 187
188 188 for tick in cb.ax.get_yticklabels():
189 189 tick.set_fontsize(ticksize)
190 190
191 191 ax_cb.yaxis.tick_right()
192 192
193 193 if '0.' in matplotlib.__version__[0:2]:
194 194 print "The matplotlib version has to be updated to 1.1 or newer"
195 195 return imesh
196 196
197 197 if '1.0.' in matplotlib.__version__[0:4]:
198 198 print "The matplotlib version has to be updated to 1.1 or newer"
199 199 return imesh
200 200
201 201 matplotlib.pyplot.tight_layout()
202 202
203 203 if XAxisAsTime:
204 204
205 205 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
206 206 ax.xaxis.set_major_formatter(FuncFormatter(func))
207 207 ax.xaxis.set_major_locator(LinearLocator(7))
208 208
209 209 matplotlib.pyplot.ion()
210 210 return imesh
211 211
212 212 def pcolor(imesh, z, xlabel='', ylabel='', title=''):
213 213
214 214 z = z.T
215 215
216 216 ax = imesh.get_axes()
217 217
218 218 printLabels(ax, xlabel, ylabel, title)
219 219
220 220 imesh.set_array(z.ravel())
221 221
222 222 def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
223 223
224 224 printLabels(ax, xlabel, ylabel, title)
225 225
226 ax.collections.remove(ax.collections[0])
226 # ax.collections.remove(ax.collections[0])
227 227
228 228 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap))
229 229
230 230 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
231 231 ticksize=9, xtick_visible=True, ytick_visible=True,
232 232 nxticks=4, nyticks=10,
233 233 grid=None):
234 234
235 235 """
236 236
237 237 Input:
238 238 grid : None, 'both', 'x', 'y'
239 239 """
240 240
241 241 matplotlib.pyplot.ioff()
242 242
243 243 lines = ax.plot(x.T, y)
244 244 leg = ax.legend(lines, legendlabels, loc='upper right')
245 245 leg.get_frame().set_alpha(0.5)
246 246 ax.set_xlim([xmin,xmax])
247 247 ax.set_ylim([ymin,ymax])
248 248 printLabels(ax, xlabel, ylabel, title)
249 249
250 250 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
251 251 ax.set_xticks(xtickspos)
252 252
253 253 for tick in ax.get_xticklabels():
254 254 tick.set_visible(xtick_visible)
255 255
256 256 for tick in ax.xaxis.get_major_ticks():
257 257 tick.label.set_fontsize(ticksize)
258 258
259 259 for tick in ax.get_yticklabels():
260 260 tick.set_visible(ytick_visible)
261 261
262 262 for tick in ax.yaxis.get_major_ticks():
263 263 tick.label.set_fontsize(ticksize)
264 264
265 265 iplot = ax.lines[-1]
266 266
267 267 if '0.' in matplotlib.__version__[0:2]:
268 268 print "The matplotlib version has to be updated to 1.1 or newer"
269 269 return iplot
270 270
271 271 if '1.0.' in matplotlib.__version__[0:4]:
272 272 print "The matplotlib version has to be updated to 1.1 or newer"
273 273 return iplot
274 274
275 275 if grid != None:
276 276 ax.grid(b=True, which='major', axis=grid)
277 277
278 278 matplotlib.pyplot.tight_layout()
279 279
280 280 matplotlib.pyplot.ion()
281 281
282 282 return iplot
283 283
284 284
285 285 def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''):
286 286
287 287 ax = iplot.get_axes()
288 288
289 289 printLabels(ax, xlabel, ylabel, title)
290 290
291 291 for i in range(len(ax.lines)):
292 292 line = ax.lines[i]
293 293 line.set_data(x[i,:],y)
294 294
295 295 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
296 296 ticksize=9, xtick_visible=True, ytick_visible=True,
297 297 nxticks=4, nyticks=10, marker='^', markersize=8, linestyle="solid",
298 298 grid=None, XAxisAsTime=False):
299 299
300 300 """
301 301
302 302 Input:
303 303 grid : None, 'both', 'x', 'y'
304 304 """
305 305
306 306 matplotlib.pyplot.ioff()
307 307
308 308 lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle)
309 309 leg = ax.legend(lines, legendlabels, loc='upper left', bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \
310 310 handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.)
311 311
312 312 for label in leg.get_texts(): label.set_fontsize(9)
313 313
314 314 ax.set_xlim([xmin,xmax])
315 315 ax.set_ylim([ymin,ymax])
316 316 printLabels(ax, xlabel, ylabel, title)
317 317
318 318 # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
319 319 # ax.set_xticks(xtickspos)
320 320
321 321 for tick in ax.get_xticklabels():
322 322 tick.set_visible(xtick_visible)
323 323
324 324 for tick in ax.xaxis.get_major_ticks():
325 325 tick.label.set_fontsize(ticksize)
326 326
327 327 for tick in ax.get_yticklabels():
328 328 tick.set_visible(ytick_visible)
329 329
330 330 for tick in ax.yaxis.get_major_ticks():
331 331 tick.label.set_fontsize(ticksize)
332 332
333 333 iplot = ax.lines[-1]
334 334
335 335 if '0.' in matplotlib.__version__[0:2]:
336 336 print "The matplotlib version has to be updated to 1.1 or newer"
337 337 return iplot
338 338
339 339 if '1.0.' in matplotlib.__version__[0:4]:
340 340 print "The matplotlib version has to be updated to 1.1 or newer"
341 341 return iplot
342 342
343 343 if grid != None:
344 344 ax.grid(b=True, which='major', axis=grid)
345 345
346 346 matplotlib.pyplot.tight_layout()
347 347
348 348 if XAxisAsTime:
349 349
350 350 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
351 351 ax.xaxis.set_major_formatter(FuncFormatter(func))
352 352 ax.xaxis.set_major_locator(LinearLocator(7))
353 353
354 354 matplotlib.pyplot.ion()
355 355
356 356 return iplot
357 357
358 358 def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''):
359 359
360 360 ax = iplot.get_axes()
361 361
362 362 printLabels(ax, xlabel, ylabel, title)
363 363
364 364 for i in range(len(ax.lines)):
365 365 line = ax.lines[i]
366 366 line.set_data(x,y[i,:])
367 367
368 368 def draw(fig):
369 369
370 370 if type(fig) == 'int':
371 371 raise ValueError, "This parameter should be of tpye matplotlib figure"
372 372
373 373 fig.canvas.draw() No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now