@@ -1,342 +1,366 | |||||
1 | import numpy |
|
1 | import numpy | |
2 | import datetime |
|
2 | import datetime | |
3 | import matplotlib |
|
3 | import matplotlib | |
4 | matplotlib.use("TKAgg") |
|
4 | matplotlib.use("GTKAgg") | |
5 | import matplotlib.pyplot |
|
5 | import matplotlib.pyplot | |
6 | import matplotlib.dates |
|
6 | import matplotlib.dates | |
7 | #import scitools.numpyutils |
|
7 | #import scitools.numpyutils | |
8 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
8 | from mpl_toolkits.axes_grid1 import make_axes_locatable | |
9 |
|
9 | |||
10 | from matplotlib.dates import DayLocator, HourLocator, MinuteLocator, SecondLocator, DateFormatter |
|
10 | from matplotlib.dates import DayLocator, HourLocator, MinuteLocator, SecondLocator, DateFormatter | |
11 | from matplotlib.ticker import FuncFormatter |
|
11 | from matplotlib.ticker import FuncFormatter | |
12 | from matplotlib.ticker import * |
|
12 | from matplotlib.ticker import * | |
13 |
|
13 | |||
14 | ########################################### |
|
14 | ########################################### | |
15 | #Actualizacion de las funciones del driver |
|
15 | #Actualizacion de las funciones del driver | |
16 | ########################################### |
|
16 | ########################################### | |
17 |
|
17 | |||
18 | def createFigure(idfigure, wintitle, width, height, facecolor="w"): |
|
18 | def createFigure(idfigure, wintitle, width, height, facecolor="w"): | |
19 |
|
19 | |||
20 | matplotlib.pyplot.ioff() |
|
20 | matplotlib.pyplot.ioff() | |
21 | fig = matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) |
|
21 | fig = matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) | |
22 | fig.canvas.manager.set_window_title(wintitle) |
|
22 | fig.canvas.manager.set_window_title(wintitle) | |
23 | fig.canvas.manager.resize(width, height) |
|
23 | fig.canvas.manager.resize(width, height) | |
24 | matplotlib.pyplot.ion() |
|
24 | matplotlib.pyplot.ion() | |
|
25 | matplotlib.pyplot.show() | |||
25 |
|
26 | |||
26 | return fig |
|
27 | return fig | |
27 |
|
28 | |||
28 | def closeFigure(): |
|
29 | def closeFigure(): | |
29 |
|
30 | |||
30 | matplotlib.pyplot.ioff() |
|
31 | matplotlib.pyplot.ioff() | |
31 | matplotlib.pyplot.show() |
|
32 | matplotlib.pyplot.show() | |
32 |
|
33 | |||
33 | return |
|
34 | return | |
34 |
|
35 | |||
35 | def saveFigure(fig, filename): |
|
36 | def saveFigure(fig, filename): | |
|
37 | ||||
|
38 | matplotlib.pyplot.ioff() | |||
36 | fig.savefig(filename) |
|
39 | fig.savefig(filename) | |
|
40 | matplotlib.pyplot.ion() | |||
37 |
|
41 | |||
38 | def setWinTitle(fig, title): |
|
42 | def setWinTitle(fig, title): | |
39 |
|
43 | |||
40 | fig.canvas.manager.set_window_title(title) |
|
44 | fig.canvas.manager.set_window_title(title) | |
41 |
|
45 | |||
42 | def setTitle(fig, title): |
|
46 | def setTitle(fig, title): | |
43 |
|
47 | |||
44 | fig.suptitle(title) |
|
48 | fig.suptitle(title) | |
45 |
|
49 | |||
46 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
50 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan): | |
47 |
|
51 | |||
|
52 | matplotlib.pyplot.ioff() | |||
48 | matplotlib.pyplot.figure(fig.number) |
|
53 | matplotlib.pyplot.figure(fig.number) | |
49 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), |
|
54 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), | |
50 | (xpos, ypos), |
|
55 | (xpos, ypos), | |
51 | colspan=colspan, |
|
56 | colspan=colspan, | |
52 | rowspan=rowspan) |
|
57 | rowspan=rowspan) | |
|
58 | ||||
|
59 | matplotlib.pyplot.ion() | |||
53 | return axes |
|
60 | return axes | |
54 |
|
61 | |||
55 | def setAxesText(ax, text): |
|
62 | def setAxesText(ax, text): | |
56 |
|
63 | |||
57 | ax.annotate(text, |
|
64 | ax.annotate(text, | |
58 | xy = (.1, .99), |
|
65 | xy = (.1, .99), | |
59 | xycoords = 'figure fraction', |
|
66 | xycoords = 'figure fraction', | |
60 | horizontalalignment = 'left', |
|
67 | horizontalalignment = 'left', | |
61 | verticalalignment = 'top', |
|
68 | verticalalignment = 'top', | |
62 | fontsize = 10) |
|
69 | fontsize = 10) | |
63 |
|
70 | |||
64 | def printLabels(ax, xlabel, ylabel, title): |
|
71 | def printLabels(ax, xlabel, ylabel, title): | |
65 |
|
72 | |||
66 | ax.set_xlabel(xlabel, size=11) |
|
73 | ax.set_xlabel(xlabel, size=11) | |
67 | ax.set_ylabel(ylabel, size=11) |
|
74 | ax.set_ylabel(ylabel, size=11) | |
68 | ax.set_title(title, size=12) |
|
75 | ax.set_title(title, size=12) | |
69 |
|
76 | |||
70 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', |
|
77 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', | |
71 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
78 | ticksize=9, xtick_visible=True, ytick_visible=True, | |
72 | nxticks=4, nyticks=10, |
|
79 | nxticks=4, nyticks=10, | |
73 | grid=None): |
|
80 | grid=None): | |
74 |
|
81 | |||
75 | """ |
|
82 | """ | |
76 |
|
83 | |||
77 | Input: |
|
84 | Input: | |
78 | grid : None, 'both', 'x', 'y' |
|
85 | grid : None, 'both', 'x', 'y' | |
79 | """ |
|
86 | """ | |
80 |
|
|
87 | ||
81 | ax.plot(x, y) |
|
88 | matplotlib.pyplot.ioff() | |
|
89 | ||||
82 | ax.set_xlim([xmin,xmax]) |
|
90 | ax.set_xlim([xmin,xmax]) | |
83 | ax.set_ylim([ymin,ymax]) |
|
91 | ax.set_ylim([ymin,ymax]) | |
84 |
|
92 | |||
85 | printLabels(ax, xlabel, ylabel, title) |
|
93 | printLabels(ax, xlabel, ylabel, title) | |
86 |
|
94 | |||
87 | ###################################################### |
|
95 | ###################################################### | |
88 | if (xmax-xmin)<=1: |
|
96 | if (xmax-xmin)<=1: | |
89 | xtickspos = numpy.linspace(xmin,xmax,nxticks) |
|
97 | xtickspos = numpy.linspace(xmin,xmax,nxticks) | |
90 | xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos]) |
|
98 | xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos]) | |
91 | ax.set_xticks(xtickspos) |
|
99 | ax.set_xticks(xtickspos) | |
92 | else: |
|
100 | else: | |
93 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
101 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) | |
94 | ax.set_xticks(xtickspos) |
|
102 | ax.set_xticks(xtickspos) | |
95 |
|
103 | |||
96 | for tick in ax.get_xticklabels(): |
|
104 | for tick in ax.get_xticklabels(): | |
97 | tick.set_visible(xtick_visible) |
|
105 | tick.set_visible(xtick_visible) | |
98 |
|
106 | |||
99 | for tick in ax.xaxis.get_major_ticks(): |
|
107 | for tick in ax.xaxis.get_major_ticks(): | |
100 | tick.label.set_fontsize(ticksize) |
|
108 | tick.label.set_fontsize(ticksize) | |
101 |
|
109 | |||
102 | ###################################################### |
|
110 | ###################################################### | |
103 | for tick in ax.get_yticklabels(): |
|
111 | for tick in ax.get_yticklabels(): | |
104 | tick.set_visible(ytick_visible) |
|
112 | tick.set_visible(ytick_visible) | |
105 |
|
113 | |||
106 | for tick in ax.yaxis.get_major_ticks(): |
|
114 | for tick in ax.yaxis.get_major_ticks(): | |
107 | tick.label.set_fontsize(ticksize) |
|
115 | tick.label.set_fontsize(ticksize) | |
108 |
|
|
116 | ||
|
117 | ax.plot(x, y) | |||
109 | iplot = ax.lines[-1] |
|
118 | iplot = ax.lines[-1] | |
110 |
|
119 | |||
111 | ###################################################### |
|
120 | ###################################################### | |
112 | if '0.' in matplotlib.__version__[0:2]: |
|
121 | if '0.' in matplotlib.__version__[0:2]: | |
113 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
122 | print "The matplotlib version has to be updated to 1.1 or newer" | |
114 | return iplot |
|
123 | return iplot | |
115 |
|
124 | |||
116 | if '1.0.' in matplotlib.__version__[0:4]: |
|
125 | if '1.0.' in matplotlib.__version__[0:4]: | |
117 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
126 | print "The matplotlib version has to be updated to 1.1 or newer" | |
118 | return iplot |
|
127 | return iplot | |
119 |
|
128 | |||
120 | if grid != None: |
|
129 | if grid != None: | |
121 | ax.grid(b=True, which='major', axis=grid) |
|
130 | ax.grid(b=True, which='major', axis=grid) | |
122 |
|
131 | |||
123 | matplotlib.pyplot.tight_layout() |
|
132 | matplotlib.pyplot.tight_layout() | |
124 |
|
133 | |||
|
134 | matplotlib.pyplot.ion() | |||
|
135 | ||||
125 | return iplot |
|
136 | return iplot | |
126 |
|
137 | |||
|
138 | def set_linedata(ax, x, y, idline): | |||
|
139 | ||||
|
140 | ax.lines[idline].set_data(x,y) | |||
|
141 | ||||
127 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
142 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): | |
128 |
|
143 | |||
129 | ax = iplot.get_axes() |
|
144 | ax = iplot.get_axes() | |
130 |
|
145 | |||
131 | printLabels(ax, xlabel, ylabel, title) |
|
146 | printLabels(ax, xlabel, ylabel, title) | |
132 |
|
147 | |||
133 | set_linedata(ax, x, y, idline=0) |
|
148 | set_linedata(ax, x, y, idline=0) | |
134 |
|
149 | |||
135 | def addpline(ax, x, y, color, linestyle, lw): |
|
150 | def addpline(ax, x, y, color, linestyle, lw): | |
|
151 | ||||
136 | ax.plot(x,y,color=color,linestyle=linestyle,lw=lw) |
|
152 | ax.plot(x,y,color=color,linestyle=linestyle,lw=lw) | |
137 |
|
153 | |||
138 |
|
154 | |||
139 | def set_linedata(ax, x, y, idline): |
|
155 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, | |
140 | ax.lines[idline].set_data(x,y) |
|
156 | xlabel='', ylabel='', title='', ticksize = 9, | |
|
157 | colormap='jet',cblabel='', cbsize="5%", | |||
|
158 | XAxisAsTime=False): | |||
|
159 | ||||
|
160 | matplotlib.pyplot.ioff() | |||
|
161 | ||||
|
162 | divider = make_axes_locatable(ax) | |||
|
163 | ax_cb = divider.new_horizontal(size=cbsize, pad=0.05) | |||
|
164 | fig = ax.get_figure() | |||
|
165 | fig.add_axes(ax_cb) | |||
|
166 | ||||
|
167 | ax.set_xlim([xmin,xmax]) | |||
|
168 | ax.set_ylim([ymin,ymax]) | |||
|
169 | ||||
|
170 | printLabels(ax, xlabel, ylabel, title) | |||
|
171 | ||||
|
172 | imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) | |||
|
173 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) | |||
|
174 | cb.set_label(cblabel) | |||
|
175 | ||||
|
176 | # for tl in ax_cb.get_yticklabels(): | |||
|
177 | # tl.set_visible(True) | |||
|
178 | ||||
|
179 | for tick in ax.yaxis.get_major_ticks(): | |||
|
180 | tick.label.set_fontsize(ticksize) | |||
|
181 | ||||
|
182 | for tick in ax.xaxis.get_major_ticks(): | |||
|
183 | tick.label.set_fontsize(ticksize) | |||
|
184 | ||||
|
185 | for tick in cb.ax.get_yticklabels(): | |||
|
186 | tick.set_fontsize(ticksize) | |||
|
187 | ||||
|
188 | ax_cb.yaxis.tick_right() | |||
|
189 | ||||
|
190 | if '0.' in matplotlib.__version__[0:2]: | |||
|
191 | print "The matplotlib version has to be updated to 1.1 or newer" | |||
|
192 | return imesh | |||
|
193 | ||||
|
194 | if '1.0.' in matplotlib.__version__[0:4]: | |||
|
195 | print "The matplotlib version has to be updated to 1.1 or newer" | |||
|
196 | return imesh | |||
|
197 | ||||
|
198 | matplotlib.pyplot.tight_layout() | |||
|
199 | ||||
|
200 | if XAxisAsTime: | |||
|
201 | ||||
|
202 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) | |||
|
203 | ax.xaxis.set_major_formatter(FuncFormatter(func)) | |||
|
204 | ax.xaxis.set_major_locator(LinearLocator(7)) | |||
|
205 | ||||
|
206 | matplotlib.pyplot.ion() | |||
|
207 | return imesh | |||
|
208 | ||||
|
209 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): | |||
|
210 | ||||
|
211 | z = z.T | |||
|
212 | ||||
|
213 | ax = imesh.get_axes() | |||
|
214 | ||||
|
215 | printLabels(ax, xlabel, ylabel, title) | |||
|
216 | ||||
|
217 | imesh.set_array(z.ravel()) | |||
|
218 | ||||
|
219 | def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): | |||
|
220 | ||||
|
221 | printLabels(ax, xlabel, ylabel, title) | |||
|
222 | ||||
|
223 | imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) | |||
141 |
|
224 | |||
142 | def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, |
|
225 | def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, | |
143 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
226 | ticksize=9, xtick_visible=True, ytick_visible=True, | |
144 | nxticks=4, nyticks=10, |
|
227 | nxticks=4, nyticks=10, | |
145 | grid=None): |
|
228 | grid=None): | |
146 |
|
229 | |||
147 | """ |
|
230 | """ | |
148 |
|
231 | |||
149 | Input: |
|
232 | Input: | |
150 | grid : None, 'both', 'x', 'y' |
|
233 | grid : None, 'both', 'x', 'y' | |
151 | """ |
|
234 | """ | |
152 |
|
|
235 | ||
|
236 | matplotlib.pyplot.ioff() | |||
|
237 | ||||
153 | lines = ax.plot(x.T, y) |
|
238 | lines = ax.plot(x.T, y) | |
154 | leg = ax.legend(lines, legendlabels, loc='upper right') |
|
239 | leg = ax.legend(lines, legendlabels, loc='upper right') | |
155 | leg.get_frame().set_alpha(0.5) |
|
240 | leg.get_frame().set_alpha(0.5) | |
156 | ax.set_xlim([xmin,xmax]) |
|
241 | ax.set_xlim([xmin,xmax]) | |
157 | ax.set_ylim([ymin,ymax]) |
|
242 | ax.set_ylim([ymin,ymax]) | |
158 | printLabels(ax, xlabel, ylabel, title) |
|
243 | printLabels(ax, xlabel, ylabel, title) | |
159 |
|
244 | |||
160 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
245 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) | |
161 | ax.set_xticks(xtickspos) |
|
246 | ax.set_xticks(xtickspos) | |
162 |
|
247 | |||
163 | for tick in ax.get_xticklabels(): |
|
248 | for tick in ax.get_xticklabels(): | |
164 | tick.set_visible(xtick_visible) |
|
249 | tick.set_visible(xtick_visible) | |
165 |
|
250 | |||
166 | for tick in ax.xaxis.get_major_ticks(): |
|
251 | for tick in ax.xaxis.get_major_ticks(): | |
167 | tick.label.set_fontsize(ticksize) |
|
252 | tick.label.set_fontsize(ticksize) | |
168 |
|
253 | |||
169 | for tick in ax.get_yticklabels(): |
|
254 | for tick in ax.get_yticklabels(): | |
170 | tick.set_visible(ytick_visible) |
|
255 | tick.set_visible(ytick_visible) | |
171 |
|
256 | |||
172 | for tick in ax.yaxis.get_major_ticks(): |
|
257 | for tick in ax.yaxis.get_major_ticks(): | |
173 | tick.label.set_fontsize(ticksize) |
|
258 | tick.label.set_fontsize(ticksize) | |
174 |
|
259 | |||
175 | iplot = ax.lines[-1] |
|
260 | iplot = ax.lines[-1] | |
176 |
|
261 | |||
177 | if '0.' in matplotlib.__version__[0:2]: |
|
262 | if '0.' in matplotlib.__version__[0:2]: | |
178 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
263 | print "The matplotlib version has to be updated to 1.1 or newer" | |
179 | return iplot |
|
264 | return iplot | |
180 |
|
265 | |||
181 | if '1.0.' in matplotlib.__version__[0:4]: |
|
266 | if '1.0.' in matplotlib.__version__[0:4]: | |
182 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
267 | print "The matplotlib version has to be updated to 1.1 or newer" | |
183 | return iplot |
|
268 | return iplot | |
184 |
|
269 | |||
185 | if grid != None: |
|
270 | if grid != None: | |
186 | ax.grid(b=True, which='major', axis=grid) |
|
271 | ax.grid(b=True, which='major', axis=grid) | |
187 |
|
272 | |||
188 | matplotlib.pyplot.tight_layout() |
|
273 | matplotlib.pyplot.tight_layout() | |
189 |
|
274 | |||
|
275 | matplotlib.pyplot.ion() | |||
|
276 | ||||
190 | return iplot |
|
277 | return iplot | |
191 |
|
278 | |||
192 |
|
279 | |||
193 | def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
280 | def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''): | |
194 |
|
281 | |||
195 | ax = iplot.get_axes() |
|
282 | ax = iplot.get_axes() | |
196 |
|
283 | |||
197 | printLabels(ax, xlabel, ylabel, title) |
|
284 | printLabels(ax, xlabel, ylabel, title) | |
198 |
|
285 | |||
199 | for i in range(len(ax.lines)): |
|
286 | for i in range(len(ax.lines)): | |
200 | line = ax.lines[i] |
|
287 | line = ax.lines[i] | |
201 | line.set_data(x[i,:],y) |
|
288 | line.set_data(x[i,:],y) | |
202 |
|
289 | |||
203 | def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, |
|
290 | def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, | |
204 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
291 | ticksize=9, xtick_visible=True, ytick_visible=True, | |
205 | nxticks=4, nyticks=10, marker='^', markersize=8, linestyle="solid", |
|
292 | nxticks=4, nyticks=10, marker='^', markersize=8, linestyle="solid", | |
206 | grid=None, XAxisAsTime=False): |
|
293 | grid=None, XAxisAsTime=False): | |
207 |
|
294 | |||
208 | """ |
|
295 | """ | |
209 |
|
296 | |||
210 | Input: |
|
297 | Input: | |
211 | grid : None, 'both', 'x', 'y' |
|
298 | grid : None, 'both', 'x', 'y' | |
212 | """ |
|
299 | """ | |
213 |
|
300 | |||
|
301 | matplotlib.pyplot.ioff() | |||
|
302 | ||||
214 | lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle) |
|
303 | lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle) | |
215 | leg = ax.legend(lines, legendlabels, bbox_to_anchor=(1.05, 1), loc='upper right', numpoints=1, handlelength=1.5, \ |
|
304 | leg = ax.legend(lines, legendlabels, bbox_to_anchor=(1.05, 1), loc='upper right', numpoints=1, handlelength=1.5, \ | |
216 | handletextpad=0.5, borderpad=0.2, labelspacing=0.2, borderaxespad=0.) |
|
305 | handletextpad=0.5, borderpad=0.2, labelspacing=0.2, borderaxespad=0.) | |
217 |
|
306 | |||
218 | ax.set_xlim([xmin,xmax]) |
|
307 | ax.set_xlim([xmin,xmax]) | |
219 | ax.set_ylim([ymin,ymax]) |
|
308 | ax.set_ylim([ymin,ymax]) | |
220 | printLabels(ax, xlabel, ylabel, title) |
|
309 | printLabels(ax, xlabel, ylabel, title) | |
221 |
|
310 | |||
222 | # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
311 | # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) | |
223 | # ax.set_xticks(xtickspos) |
|
312 | # ax.set_xticks(xtickspos) | |
224 |
|
313 | |||
225 | for tick in ax.get_xticklabels(): |
|
314 | for tick in ax.get_xticklabels(): | |
226 | tick.set_visible(xtick_visible) |
|
315 | tick.set_visible(xtick_visible) | |
227 |
|
316 | |||
228 | for tick in ax.xaxis.get_major_ticks(): |
|
317 | for tick in ax.xaxis.get_major_ticks(): | |
229 | tick.label.set_fontsize(ticksize) |
|
318 | tick.label.set_fontsize(ticksize) | |
230 |
|
319 | |||
231 | for tick in ax.get_yticklabels(): |
|
320 | for tick in ax.get_yticklabels(): | |
232 | tick.set_visible(ytick_visible) |
|
321 | tick.set_visible(ytick_visible) | |
233 |
|
322 | |||
234 | for tick in ax.yaxis.get_major_ticks(): |
|
323 | for tick in ax.yaxis.get_major_ticks(): | |
235 | tick.label.set_fontsize(ticksize) |
|
324 | tick.label.set_fontsize(ticksize) | |
236 |
|
325 | |||
237 | iplot = ax.lines[-1] |
|
326 | iplot = ax.lines[-1] | |
238 |
|
327 | |||
239 | if '0.' in matplotlib.__version__[0:2]: |
|
328 | if '0.' in matplotlib.__version__[0:2]: | |
240 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
329 | print "The matplotlib version has to be updated to 1.1 or newer" | |
241 | return iplot |
|
330 | return iplot | |
242 |
|
331 | |||
243 | if '1.0.' in matplotlib.__version__[0:4]: |
|
332 | if '1.0.' in matplotlib.__version__[0:4]: | |
244 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
333 | print "The matplotlib version has to be updated to 1.1 or newer" | |
245 | return iplot |
|
334 | return iplot | |
246 |
|
335 | |||
247 | if grid != None: |
|
336 | if grid != None: | |
248 | ax.grid(b=True, which='major', axis=grid) |
|
337 | ax.grid(b=True, which='major', axis=grid) | |
249 |
|
338 | |||
250 | matplotlib.pyplot.tight_layout() |
|
339 | matplotlib.pyplot.tight_layout() | |
251 |
|
340 | |||
252 | if XAxisAsTime: |
|
341 | if XAxisAsTime: | |
253 |
|
342 | |||
254 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) |
|
343 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) | |
255 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
344 | ax.xaxis.set_major_formatter(FuncFormatter(func)) | |
256 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
345 | ax.xaxis.set_major_locator(LinearLocator(7)) | |
257 |
|
346 | |||
|
347 | matplotlib.pyplot.ion() | |||
|
348 | ||||
258 | return iplot |
|
349 | return iplot | |
259 |
|
350 | |||
260 | def pmultilineinyaxis(iplot, x, y, xlabel='', ylabel='', title=''): |
|
351 | def pmultilineinyaxis(iplot, x, y, xlabel='', ylabel='', title=''): | |
261 |
|
352 | |||
262 | ax = iplot.get_axes() |
|
353 | ax = iplot.get_axes() | |
263 |
|
354 | |||
264 | printLabels(ax, xlabel, ylabel, title) |
|
355 | printLabels(ax, xlabel, ylabel, title) | |
265 |
|
356 | |||
266 | for i in range(len(ax.lines)): |
|
357 | for i in range(len(ax.lines)): | |
267 | line = ax.lines[i] |
|
358 | line = ax.lines[i] | |
268 | line.set_data(x,y[i,:]) |
|
359 | line.set_data(x,y[i,:]) | |
269 |
|
360 | |||
270 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, |
|
|||
271 | xlabel='', ylabel='', title='', ticksize = 9, |
|
|||
272 | colormap='jet',cblabel='', cbsize="5%", |
|
|||
273 | XAxisAsTime=False): |
|
|||
274 |
|
||||
275 | divider = make_axes_locatable(ax) |
|
|||
276 | ax_cb = divider.new_horizontal(size=cbsize, pad=0.05) |
|
|||
277 | fig = ax.get_figure() |
|
|||
278 | fig.add_axes(ax_cb) |
|
|||
279 |
|
||||
280 | ax.set_xlim([xmin,xmax]) |
|
|||
281 | ax.set_ylim([ymin,ymax]) |
|
|||
282 |
|
||||
283 | printLabels(ax, xlabel, ylabel, title) |
|
|||
284 |
|
||||
285 | imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
|||
286 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) |
|
|||
287 | cb.set_label(cblabel) |
|
|||
288 |
|
||||
289 | # for tl in ax_cb.get_yticklabels(): |
|
|||
290 | # tl.set_visible(True) |
|
|||
291 |
|
||||
292 | for tick in ax.yaxis.get_major_ticks(): |
|
|||
293 | tick.label.set_fontsize(ticksize) |
|
|||
294 |
|
||||
295 | for tick in ax.xaxis.get_major_ticks(): |
|
|||
296 | tick.label.set_fontsize(ticksize) |
|
|||
297 |
|
||||
298 | for tick in cb.ax.get_yticklabels(): |
|
|||
299 | tick.set_fontsize(ticksize) |
|
|||
300 |
|
||||
301 | ax_cb.yaxis.tick_right() |
|
|||
302 |
|
||||
303 | if '0.' in matplotlib.__version__[0:2]: |
|
|||
304 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
|||
305 | return imesh |
|
|||
306 |
|
||||
307 | if '1.0.' in matplotlib.__version__[0:4]: |
|
|||
308 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
|||
309 | return imesh |
|
|||
310 |
|
||||
311 | matplotlib.pyplot.tight_layout() |
|
|||
312 |
|
||||
313 | if XAxisAsTime: |
|
|||
314 |
|
||||
315 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) |
|
|||
316 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
|||
317 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
|||
318 |
|
||||
319 | return imesh |
|
|||
320 |
|
||||
321 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): |
|
|||
322 |
|
||||
323 | z = z.T |
|
|||
324 |
|
||||
325 | ax = imesh.get_axes() |
|
|||
326 |
|
||||
327 | printLabels(ax, xlabel, ylabel, title) |
|
|||
328 |
|
||||
329 | imesh.set_array(z.ravel()) |
|
|||
330 |
|
||||
331 | def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): |
|
|||
332 |
|
||||
333 | printLabels(ax, xlabel, ylabel, title) |
|
|||
334 |
|
||||
335 | imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
|||
336 |
|
||||
337 | def draw(fig): |
|
361 | def draw(fig): | |
338 |
|
362 | |||
339 | if type(fig) == 'int': |
|
363 | if type(fig) == 'int': | |
340 | raise ValueError, "This parameter should be of tpye matplotlib figure" |
|
364 | raise ValueError, "This parameter should be of tpye matplotlib figure" | |
341 |
|
365 | |||
342 | fig.canvas.draw() No newline at end of file |
|
366 | fig.canvas.draw() |
General Comments 0
You need to be logged in to leave comments.
Login now