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