| [13771] | 1 | try:
|
|---|
| [16137] | 2 | from matplotlib.ticker import MaxNLocator
|
|---|
| [13771] | 3 | import pylab as p
|
|---|
| 4 | except ImportError:
|
|---|
| 5 | print "could not import pylab, matplotlib has not been installed, no plotting capabilities enabled"
|
|---|
| 6 |
|
|---|
| [13417] | 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 |
|
|---|
| [13424] | 21 | #font {{{
|
|---|
| [13417] | 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 | }
|
|---|
| [13424] | 30 | #}}}
|
|---|
| [13417] | 31 |
|
|---|
| [13424] | 32 | #title {{{
|
|---|
| [13417] | 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)
|
|---|
| [13424] | 48 | #}}}
|
|---|
| [13417] | 49 |
|
|---|
| [13424] | 50 | #xlabel, ylabel, zlabel {{{
|
|---|
| [13417] | 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)
|
|---|
| [13424] | 71 | #}}}
|
|---|
| [13417] | 72 |
|
|---|
| [13424] | 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 | #}}}
|
|---|
| [13417] | 93 |
|
|---|
| [13424] | 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 |
|
|---|
| [14310] | 109 | #ticklabel notation {{{
|
|---|
| 110 | p.gca().ticklabel_format(style='sci',scilimits=(0,0))
|
|---|
| 111 | #}}}
|
|---|
| 112 |
|
|---|
| [13424] | 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 | #}}}
|
|---|
| [14310] | 122 |
|
|---|
| [13417] | 123 | #view
|
|---|
| 124 |
|
|---|
| 125 | #axis
|
|---|
| 126 |
|
|---|
| 127 | #box
|
|---|
| 128 |
|
|---|
| [13424] | 129 | #xlim, ylim, zlim {{{
|
|---|
| [13417] | 130 | if options.exist('xlim'):
|
|---|
| 131 | p.xlim(options.getfieldvalue('xlim'))
|
|---|
| 132 | if options.exist('ylim'):
|
|---|
| 133 | p.xlim(options.getfieldvalue('ylim'))
|
|---|
| 134 | if options.exist('zlim'):
|
|---|
| 135 | p.xlim(options.getfieldvalue('zlim'))
|
|---|
| [13424] | 136 | #}}}
|
|---|
| [13417] | 137 |
|
|---|
| 138 | #latlon
|
|---|
| 139 |
|
|---|
| 140 | #Basinzoom
|
|---|
| 141 |
|
|---|
| 142 | #ShowBasins
|
|---|
| 143 |
|
|---|
| [14310] | 144 | #clim {{{
|
|---|
| 145 | if options.exist('clim'):
|
|---|
| 146 | lims=options.getfieldvalue('clim')
|
|---|
| 147 | if len(lims)!=2:
|
|---|
| 148 | print 'WARNING: clim should be passed as a list of length 2'
|
|---|
| 149 | else:
|
|---|
| 150 | p.clim(lims[0],lims[1])
|
|---|
| 151 | #}}}
|
|---|
| [13417] | 152 |
|
|---|
| 153 | #shading
|
|---|
| 154 |
|
|---|
| [13424] | 155 | #grid {{{
|
|---|
| [13417] | 156 | if options.exist('grid'):
|
|---|
| [13440] | 157 | if 'on' in options.getfieldvalue('grid','on'):
|
|---|
| 158 | p.grid()
|
|---|
| [13424] | 159 | #}}}
|
|---|
| [13417] | 160 |
|
|---|
| 161 | #colormap
|
|---|
| 162 |
|
|---|
| 163 | #wrapping
|
|---|
| 164 |
|
|---|
| [13440] | 165 | #colorbar {{{
|
|---|
| [14310] | 166 | if options.getfieldvalue('colorbar','off')==1:
|
|---|
| 167 | cb=p.colorbar()
|
|---|
| 168 | cb.locator=MaxNLocator(nbins=5) # default 5 ticks
|
|---|
| 169 | cb.update_ticks()
|
|---|
| 170 | if options.exist('colorbarnumticks'):
|
|---|
| 171 | cb.locator=MaxNLocator(nbins=options.getfieldvalue('colorbarnumticks',5))
|
|---|
| 172 | cb.update_ticks()
|
|---|
| [13440] | 173 | #}}}
|
|---|
| [13417] | 174 |
|
|---|
| 175 | #area
|
|---|
| 176 |
|
|---|
| 177 | #expdisp
|
|---|
| 178 |
|
|---|
| 179 | #text
|
|---|
| 180 |
|
|---|
| 181 | #north arrow
|
|---|
| 182 |
|
|---|
| 183 | #scale ruler
|
|---|
| 184 |
|
|---|
| 185 | #streamlines
|
|---|
| 186 |
|
|---|
| 187 | #contours
|
|---|
| 188 |
|
|---|
| 189 | #axis positions
|
|---|
| 190 |
|
|---|
| 191 | #figure position
|
|---|
| 192 |
|
|---|
| 193 | #axes position
|
|---|
| 194 |
|
|---|
| 195 | #showregion
|
|---|
| 196 |
|
|---|
| 197 | #flat edges of a partition
|
|---|
| 198 |
|
|---|
| 199 | #scatter
|
|---|
| 200 |
|
|---|
| 201 | #backgroundcolor
|
|---|
| 202 |
|
|---|
| 203 | #figurebackgroundcolor
|
|---|
| 204 |
|
|---|
| 205 | #lighting
|
|---|
| 206 |
|
|---|
| 207 | #point cloud
|
|---|
| 208 |
|
|---|
| 209 | #inset
|
|---|