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