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