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