##// END OF EJS Templates
mpldriver updated
Miguel Valdez -
r767:acac4be902db
parent child
Show More
@@ -1,448 +1,448
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, linestyle=linestyle, marker=marker, markersize=markersize)
333 lines = ax.plot(x, y.T)
334 leg = ax.legend(lines, legendlabels, loc='upper left', bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \
334 leg = ax.legend(lines, legendlabels, loc=1, 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 for label in leg.get_texts(): label.set_fontsize(9)
337 for label in leg.get_texts(): label.set_fontsize(9)
338
338
339 ax.set_xlim([xmin,xmax])
339 ax.set_xlim([xmin,xmax])
340 ax.set_ylim([ymin,ymax])
340 ax.set_ylim([ymin,ymax])
341 printLabels(ax, xlabel, ylabel, title)
341 printLabels(ax, xlabel, ylabel, title)
342
342
343 # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
343 # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
344 # ax.set_xticks(xtickspos)
344 # ax.set_xticks(xtickspos)
345
345
346 for tick in ax.get_xticklabels():
346 for tick in ax.get_xticklabels():
347 tick.set_visible(xtick_visible)
347 tick.set_visible(xtick_visible)
348
348
349 for tick in ax.xaxis.get_major_ticks():
349 for tick in ax.xaxis.get_major_ticks():
350 tick.label.set_fontsize(ticksize)
350 tick.label.set_fontsize(ticksize)
351
351
352 for tick in ax.get_yticklabels():
352 for tick in ax.get_yticklabels():
353 tick.set_visible(ytick_visible)
353 tick.set_visible(ytick_visible)
354
354
355 for tick in ax.yaxis.get_major_ticks():
355 for tick in ax.yaxis.get_major_ticks():
356 tick.label.set_fontsize(ticksize)
356 tick.label.set_fontsize(ticksize)
357
357
358 iplot = ax.lines[-1]
358 iplot = ax.lines[-1]
359
359
360 if '0.' in matplotlib.__version__[0:2]:
360 if '0.' in matplotlib.__version__[0:2]:
361 print "The matplotlib version has to be updated to 1.1 or newer"
361 print "The matplotlib version has to be updated to 1.1 or newer"
362 return iplot
362 return iplot
363
363
364 if '1.0.' in matplotlib.__version__[0:4]:
364 if '1.0.' in matplotlib.__version__[0:4]:
365 print "The matplotlib version has to be updated to 1.1 or newer"
365 print "The matplotlib version has to be updated to 1.1 or newer"
366 return iplot
366 return iplot
367
367
368 if grid != None:
368 if grid != None:
369 ax.grid(b=True, which='major', axis=grid)
369 ax.grid(b=True, which='major', axis=grid)
370
370
371 matplotlib.pyplot.tight_layout()
371 matplotlib.pyplot.tight_layout()
372
372
373 if XAxisAsTime:
373 if XAxisAsTime:
374
374
375 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
375 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
376 ax.xaxis.set_major_formatter(FuncFormatter(func))
376 ax.xaxis.set_major_formatter(FuncFormatter(func))
377 ax.xaxis.set_major_locator(LinearLocator(7))
377 ax.xaxis.set_major_locator(LinearLocator(7))
378
378
379 matplotlib.pyplot.ion()
379 matplotlib.pyplot.ion()
380
380
381 return iplot
381 return iplot
382
382
383 def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''):
383 def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''):
384
384
385 ax = iplot.get_axes()
385 ax = iplot.get_axes()
386
386
387 printLabels(ax, xlabel, ylabel, title)
387 printLabels(ax, xlabel, ylabel, title)
388
388
389 for i in range(len(ax.lines)):
389 for i in range(len(ax.lines)):
390 line = ax.lines[i]
390 line = ax.lines[i]
391 line.set_data(x,y[i,:])
391 line.set_data(x,y[i,:])
392
392
393 def createPolar(ax, x, y,
393 def createPolar(ax, x, y,
394 xlabel='', ylabel='', title='', ticksize = 9,
394 xlabel='', ylabel='', title='', ticksize = 9,
395 colormap='jet',cblabel='', cbsize="5%",
395 colormap='jet',cblabel='', cbsize="5%",
396 XAxisAsTime=False):
396 XAxisAsTime=False):
397
397
398 matplotlib.pyplot.ioff()
398 matplotlib.pyplot.ioff()
399
399
400 ax.plot(x,y,'bo', markersize=5)
400 ax.plot(x,y,'bo', markersize=5)
401 # ax.set_rmax(90)
401 # ax.set_rmax(90)
402 ax.set_ylim(0,90)
402 ax.set_ylim(0,90)
403 ax.set_yticks(numpy.arange(0,90,20))
403 ax.set_yticks(numpy.arange(0,90,20))
404 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11')
404 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11')
405 # ax.text(0, 50, ylabel, rotation='vertical', va ='center', ha = 'left' ,size='11')
405 # ax.text(0, 50, ylabel, rotation='vertical', va ='center', ha = 'left' ,size='11')
406 # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical')
406 # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical')
407 ax.yaxis.labelpad = 230
407 ax.yaxis.labelpad = 230
408 printLabels(ax, xlabel, ylabel, title)
408 printLabels(ax, xlabel, ylabel, title)
409 iplot = ax.lines[-1]
409 iplot = ax.lines[-1]
410
410
411 if '0.' in matplotlib.__version__[0:2]:
411 if '0.' in matplotlib.__version__[0:2]:
412 print "The matplotlib version has to be updated to 1.1 or newer"
412 print "The matplotlib version has to be updated to 1.1 or newer"
413 return iplot
413 return iplot
414
414
415 if '1.0.' in matplotlib.__version__[0:4]:
415 if '1.0.' in matplotlib.__version__[0:4]:
416 print "The matplotlib version has to be updated to 1.1 or newer"
416 print "The matplotlib version has to be updated to 1.1 or newer"
417 return iplot
417 return iplot
418
418
419 # if grid != None:
419 # if grid != None:
420 # ax.grid(b=True, which='major', axis=grid)
420 # ax.grid(b=True, which='major', axis=grid)
421
421
422 matplotlib.pyplot.tight_layout()
422 matplotlib.pyplot.tight_layout()
423
423
424 matplotlib.pyplot.ion()
424 matplotlib.pyplot.ion()
425
425
426
426
427 return iplot
427 return iplot
428
428
429 def polar(iplot, x, y, xlabel='', ylabel='', title=''):
429 def polar(iplot, x, y, xlabel='', ylabel='', title=''):
430
430
431 ax = iplot.get_axes()
431 ax = iplot.get_axes()
432
432
433 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11')
433 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11')
434 printLabels(ax, xlabel, ylabel, title)
434 printLabels(ax, xlabel, ylabel, title)
435
435
436 set_linedata(ax, x, y, idline=0)
436 set_linedata(ax, x, y, idline=0)
437
437
438 def draw(fig):
438 def draw(fig):
439
439
440 if type(fig) == 'int':
440 if type(fig) == 'int':
441 raise ValueError, "Error drawing: Fig parameter should be a matplotlib figure object figure"
441 raise ValueError, "Error drawing: Fig parameter should be a matplotlib figure object figure"
442
442
443 fig.canvas.draw()
443 fig.canvas.draw()
444
444
445 def pause(interval=0.000001):
445 def pause(interval=0.000001):
446
446
447 matplotlib.pyplot.pause(interval)
447 matplotlib.pyplot.pause(interval)
448 No newline at end of file
448
General Comments 0
You need to be logged in to leave comments. Login now