| 1 | try:
|
|---|
| 2 | from matplotlib.ticker import MaxNLocator
|
|---|
| 3 | import pylab as p
|
|---|
| 4 | except ImportError:
|
|---|
| 5 | print "could not import pylab, matplotlib has not been installed, no plotting capabilities enabled"
|
|---|
| 6 |
|
|---|
| 7 | def applyoptions(md,data,options):
|
|---|
| 8 | '''
|
|---|
| 9 | APPLYOPTIONS - apply options to current plot
|
|---|
| 10 |
|
|---|
| 11 | Usage:
|
|---|
| 12 | applyoptions(md,data,options)
|
|---|
| 13 |
|
|---|
| 14 | See also: PLOTMODEL, PARSE_OPTIONS
|
|---|
| 15 | '''
|
|---|
| 16 |
|
|---|
| 17 | #some defaults (this seems to be adding a field that already exists...)
|
|---|
| 18 | #if not isnan(md.mesh.hemisphere):
|
|---|
| 19 | # options.addfielddefault('hemisphere',md.mesh.hemisphere)
|
|---|
| 20 |
|
|---|
| 21 | #font {{{
|
|---|
| 22 | fontsize=options.getfieldvalue('fontsize',14)
|
|---|
| 23 | fontweight=options.getfieldvalue('fontweight','normal')
|
|---|
| 24 | fontfamily=options.getfieldvalue('fontfamily','sans-serif')
|
|---|
| 25 | font={
|
|---|
| 26 | 'fontsize' :fontsize,
|
|---|
| 27 | 'fontweight' :fontweight,
|
|---|
| 28 | 'family' :fontfamily
|
|---|
| 29 | }
|
|---|
| 30 | #}}}
|
|---|
| 31 |
|
|---|
| 32 | #title {{{
|
|---|
| 33 | if options.exist('title'):
|
|---|
| 34 | title=options.getfieldvalue('title')
|
|---|
| 35 | if options.exist('titlefontsize'):
|
|---|
| 36 | titlefontsize=options.getfieldvalue('titlefontsize')
|
|---|
| 37 | else:
|
|---|
| 38 | titlefontsize=fontsize
|
|---|
| 39 | if options.exist('titlefontweight'):
|
|---|
| 40 | titlefontweight=options.getfieldvalue('titlefontweight')
|
|---|
| 41 | else:
|
|---|
| 42 | titlefontweight=fontweight
|
|---|
| 43 | #title font
|
|---|
| 44 | titlefont=font.copy()
|
|---|
| 45 | titlefont['size']=titlefontsize
|
|---|
| 46 | titlefont['weight']=titlefontweight
|
|---|
| 47 | p.title(title,**titlefont)
|
|---|
| 48 | #}}}
|
|---|
| 49 |
|
|---|
| 50 | #xlabel, ylabel, zlabel {{{
|
|---|
| 51 | if options.exist('labelfontsize'):
|
|---|
| 52 | labelfontsize=options.getfieldvalue('labelfontsize')
|
|---|
| 53 | else:
|
|---|
| 54 | labelfontsize=fontsize
|
|---|
| 55 | if options.exist('labelfontweight'):
|
|---|
| 56 | labelfontweight=options.getfieldvalue('labelfontweight')
|
|---|
| 57 | else:
|
|---|
| 58 | labelfontweight=fontweight
|
|---|
| 59 |
|
|---|
| 60 | #font dict for labels
|
|---|
| 61 | labelfont=font.copy()
|
|---|
| 62 | labelfont['fontsize']=labelfontsize
|
|---|
| 63 | labelfont['fontweight']=labelfontweight
|
|---|
| 64 |
|
|---|
| 65 | if options.exist('xlabel'):
|
|---|
| 66 | p.xlabel(options.getfieldvalue('xlabel'),**labelfont)
|
|---|
| 67 | if options.exist('ylabel'):
|
|---|
| 68 | p.ylabel(options.getfieldvalue('ylabel'),**labelfont)
|
|---|
| 69 | if options.exist('zlabel'):
|
|---|
| 70 | p.zlabel(options.getfieldvalue('zlabel'),**labelfont)
|
|---|
| 71 | #}}}
|
|---|
| 72 |
|
|---|
| 73 | #xticks, yticks, zticks (tick locations) {{{
|
|---|
| 74 | if options.exist('xticks'):
|
|---|
| 75 | if options.exist('xticklabels'):
|
|---|
| 76 | xticklabels=options.getfieldvalue('xticklabels')
|
|---|
| 77 | p.xticks(options.getfieldvalue('xticks'),xticklabels)
|
|---|
| 78 | else:
|
|---|
| 79 | p.xticks(options.getfieldvalue('xticks'))
|
|---|
| 80 | if options.exist('yticks'):
|
|---|
| 81 | if options.exist('yticklabels'):
|
|---|
| 82 | yticklabels=options.getfieldvalue('yticklabels')
|
|---|
| 83 | p.yticks(options.getfieldvalue('yticks'),yticklabels)
|
|---|
| 84 | else:
|
|---|
| 85 | p.yticks(options.getfieldvalue('yticks'))
|
|---|
| 86 | if options.exist('zticks'):
|
|---|
| 87 | if options.exist('zticklabels'):
|
|---|
| 88 | zticklabels=options.getfieldvalue('zticklabels')
|
|---|
| 89 | p.zticks(options.getfieldvalue('zticks'),zticklabels)
|
|---|
| 90 | else:
|
|---|
| 91 | p.zticks(options.getfieldvalue('zticks'))
|
|---|
| 92 | #}}}
|
|---|
| 93 |
|
|---|
| 94 | #xticklabels,yticklabels,zticklabels {{{
|
|---|
| 95 | if options.exist('xticklabels'):
|
|---|
| 96 | xticklabels=options.getfieldvalue('xticklabels')
|
|---|
| 97 | xtickloc=p.xticks()[0]
|
|---|
| 98 | p.xticks(xtickloc,xticklabels)
|
|---|
| 99 | if options.exist('yticklabels'):
|
|---|
| 100 | yticklabels=options.getfieldvalue('yticklabels')
|
|---|
| 101 | ytickloc=p.yticks()[0]
|
|---|
| 102 | p.yticks(ytickloc,yticklabels)
|
|---|
| 103 | if options.exist('zticklabels'):
|
|---|
| 104 | zticklabels=options.getfieldvalue('zticklabels')
|
|---|
| 105 | ztickloc=p.zticks()[0]
|
|---|
| 106 | p.zticks(ztickloc,zticklabels)
|
|---|
| 107 | #}}}
|
|---|
| 108 |
|
|---|
| 109 | #ticklabel notation {{{
|
|---|
| 110 | p.gca().ticklabel_format(style='sci',scilimits=(0,0))
|
|---|
| 111 | #}}}
|
|---|
| 112 |
|
|---|
| 113 | #ticklabelfontsize {{{
|
|---|
| 114 | if options.exist('ticklabelfontsize'):
|
|---|
| 115 | ax=p.gca()
|
|---|
| 116 | for label in ax.get_xticklabels() + ax.get_yticklabels():
|
|---|
| 117 | label.set_fontsize(options.getfieldvalue('ticklabelfontsize'))
|
|---|
| 118 | if int(md.mesh.dimension)==3:
|
|---|
| 119 | for label in ax.get_zticklabels():
|
|---|
| 120 | label.set_fontsize(options.getfieldvalue('ticklabelfontsize'))
|
|---|
| 121 | #}}}
|
|---|
| 122 |
|
|---|
| 123 | #view
|
|---|
| 124 |
|
|---|
| 125 | #axis {{{
|
|---|
| 126 | if options.exist('axis'):
|
|---|
| 127 | if options.getfieldvalue('axis',True)=='off':
|
|---|
| 128 | p.gca().ticklabel_format(style='plain')
|
|---|
| 129 | p.setp(p.gca().get_xticklabels(), visible=False)
|
|---|
| 130 | p.setp(p.gca().get_yticklabels(), visible=False)
|
|---|
| 131 | # }}}
|
|---|
| 132 |
|
|---|
| 133 | #box
|
|---|
| 134 |
|
|---|
| 135 | #xlim, ylim, zlim {{{
|
|---|
| 136 | if options.exist('xlim'):
|
|---|
| 137 | p.xlim(options.getfieldvalue('xlim'))
|
|---|
| 138 | if options.exist('ylim'):
|
|---|
| 139 | p.xlim(options.getfieldvalue('ylim'))
|
|---|
| 140 | if options.exist('zlim'):
|
|---|
| 141 | p.xlim(options.getfieldvalue('zlim'))
|
|---|
| 142 | #}}}
|
|---|
| 143 |
|
|---|
| 144 | #latlon
|
|---|
| 145 |
|
|---|
| 146 | #Basinzoom
|
|---|
| 147 |
|
|---|
| 148 | #ShowBasins
|
|---|
| 149 |
|
|---|
| 150 | #clim {{{
|
|---|
| 151 | if options.exist('clim'):
|
|---|
| 152 | lims=options.getfieldvalue('clim')
|
|---|
| 153 | if len(lims)!=2:
|
|---|
| 154 | print 'WARNING: clim should be passed as a list of length 2'
|
|---|
| 155 | else:
|
|---|
| 156 | p.clim(lims[0],lims[1])
|
|---|
| 157 | #}}}
|
|---|
| 158 |
|
|---|
| 159 | #shading
|
|---|
| 160 |
|
|---|
| 161 | #grid {{{
|
|---|
| 162 | if options.exist('grid'):
|
|---|
| 163 | if 'on' in options.getfieldvalue('grid','on'):
|
|---|
| 164 | p.grid()
|
|---|
| 165 | #}}}
|
|---|
| 166 |
|
|---|
| 167 | #colormap
|
|---|
| 168 |
|
|---|
| 169 | #wrapping
|
|---|
| 170 |
|
|---|
| 171 | #colorbar {{{
|
|---|
| 172 | if options.getfieldvalue('colorbar',1)==1:
|
|---|
| 173 | if options.exist('clim'):
|
|---|
| 174 | # build custom colorbar (does not yet allow customizing the location)
|
|---|
| 175 | fig = p.gcf()
|
|---|
| 176 | ax = p.gca()
|
|---|
| 177 | divider = make_axes_locatable(ax)
|
|---|
| 178 | cax = divider.new_horizontal("5%", pad=0.05, axes_class=maxes.Axes)
|
|---|
| 179 | fig.add_axes(cax)
|
|---|
| 180 | cmap = mpl.cm.jet
|
|---|
| 181 | norm = mpl.colors.Normalize(vmin=lims[0], vmax=lims[1])
|
|---|
| 182 | cb = mpl.colorbar.ColorbarBase(cax, cmap=cmap, norm=norm)
|
|---|
| 183 | else:
|
|---|
| 184 | cb=p.colorbar()
|
|---|
| 185 | cb.locator=MaxNLocator(nbins=5) # default 5 ticks
|
|---|
| 186 | cb.update_ticks()
|
|---|
| 187 | if options.exist('colorbarnumticks'):
|
|---|
| 188 | cb.locator=MaxNLocator(nbins=options.getfieldvalue('colorbarnumticks',5))
|
|---|
| 189 | cb.update_ticks()
|
|---|
| 190 | #}}}
|
|---|
| 191 |
|
|---|
| 192 | #area
|
|---|
| 193 |
|
|---|
| 194 | #expdisp
|
|---|
| 195 |
|
|---|
| 196 | #text
|
|---|
| 197 |
|
|---|
| 198 | #north arrow
|
|---|
| 199 |
|
|---|
| 200 | #scale ruler
|
|---|
| 201 |
|
|---|
| 202 | #streamlines
|
|---|
| 203 |
|
|---|
| 204 | #contours
|
|---|
| 205 |
|
|---|
| 206 | #axis positions
|
|---|
| 207 |
|
|---|
| 208 | #figure position
|
|---|
| 209 |
|
|---|
| 210 | #axes position
|
|---|
| 211 |
|
|---|
| 212 | #showregion
|
|---|
| 213 |
|
|---|
| 214 | #flat edges of a partition
|
|---|
| 215 |
|
|---|
| 216 | #scatter
|
|---|
| 217 |
|
|---|
| 218 | #backgroundcolor
|
|---|
| 219 |
|
|---|
| 220 | #figurebackgroundcolor
|
|---|
| 221 |
|
|---|
| 222 | #lighting
|
|---|
| 223 |
|
|---|
| 224 | #point cloud
|
|---|
| 225 |
|
|---|
| 226 | #inset
|
|---|