def save_style(self, style): current_obj = self.style_editor.textObject style = str(style) if style == current_obj.name: to_name = current_obj.To_name to_src = "default" tt_name = current_obj.Tt_name tt_src = "default" else: to_name = style to_src = current_obj.To_name tt_name = style tt_src = current_obj.Tt_name try: to = vcs.gettextorientation(to_name) except ValueError: to = vcs.createtextorientation(name=to_name, source=to_src) try: tt = vcs.gettexttable(tt_name) except ValueError: tt = vcs.createtexttable(name=tt_name, source=tt_src) get_textstyles().updated(tt_name) self.current_member.texttable = tt self.current_member.textorientation = to self.current_member = None self.sync() self.labelUpdated.emit()
def update(self): if self.canvas is None: return self.canvas.clear(render=False) template = vcs.createtemplate() template.blank() template.legend.priority = 1 # Expand template to engulf the canvas template.legend.x1 = 0.125 template.legend.y1 = 0.35 template.legend.x2 = 0.875 template.legend.y2 = 0.65 legend_size = 50 text_orientation = vcs.createtextorientation() text_orientation.height = legend_size text_orientation.halign = "center" template.legend.textorientation = text_orientation.name template.drawColorBar( self.legend.vcs_colors, self.legend.levels, self.legend.labels, ext_1=self.legend.ext_left, ext_2=self.legend.ext_right, x=self.canvas, cmap=self.legend.colormap, style=[self.legend.fill_style], index=self.legend._gm.fillareaindices, opacity=self.legend._gm.fillareaopacity, ) self.canvas.backend.renWin.Render()
def text_orientation_for_angle(self, theta, source="default"): """ Generates a text orientation that will align text to look good depending on quadrant. """ # Normalize to [0, 2*pi) while 0 > theta: theta += 2 * numpy.pi while 2 * numpy.pi <= theta: theta -= 2 * numpy.pi if 0 < theta < numpy.pi: valign = "bottom" elif 0 == theta or numpy.pi == theta: valign = "half" else: valign = "top" if numpy.pi / 2 > theta or numpy.pi * 3 / 2 < theta: halign = "left" elif numpy.allclose(numpy.pi / 2, theta) or numpy.allclose(numpy.pi * 3 / 2, theta): halign = "center" else: halign = "right" # Build new text table to = vcs.createtextorientation(source=source) to.valign = valign to.halign = halign self.to_cleanup.append(to) return to
def text_orientation_for_angle(self, theta, source="default"): """ Generates a text orientation that will align text to look good depending on quadrant. """ # Normalize to [0, 2*pi) while 0 > theta: theta += 2 * numpy.pi while 2 * numpy.pi <= theta: theta -= 2 * numpy.pi if 0 < theta < numpy.pi: valign = "bottom" elif 0 == theta or numpy.pi == theta: valign = "half" else: valign = "top" if numpy.pi / 2 > theta or numpy.pi * 3 / 2 < theta: halign = "left" elif numpy.allclose(numpy.pi / 2, theta) or numpy.allclose( numpy.pi * 3 / 2, theta): halign = "center" else: halign = "right" # Build new text table to = vcs.createtextorientation(source=source) to.valign = valign to.halign = halign self.to_cleanup.append(to) return to
def update(self): if self.canvas is None: return self.canvas.clear(render=False) template = vcs.createtemplate() template.blank() template.legend.priority = 1 # Expand template to engulf the canvas template.legend.x1 = .125 template.legend.y1 = .35 template.legend.x2 = .875 template.legend.y2 = .65 legend_size = 50 text_orientation = vcs.createtextorientation() text_orientation.height = legend_size text_orientation.halign = "center" template.legend.textorientation = text_orientation.name template.drawColorBar(self.legend.vcs_colors, self.legend.levels, self.legend.labels, ext_1=self.legend.ext_left, ext_2=self.legend.ext_right, x=self.canvas, cmap=self.legend.colormap, style=[self.legend.fill_style], index=self.legend._gm.fillareaindices, opacity=self.legend._gm.fillareaopacity) self.canvas.backend.renWin.Render()
def __init__(self): self.x1 = .12 self.x2 = .84 self.y1 = .17 self.y2 = .8 self.levels = None self.colormap = None self.fillareacolors = None self.legend = XYs(.89, .91, self.y1, self.y2) # X ticks self.xticorientation = vcs.createtextorientation() self.xticorientation.angle = 360 - 90 self.xticorientation.halign = 'right' self.xticorientation.height = 10 # Y ticks self.yticorientation = vcs.createtextorientation() self.yticorientation.angle = 0 self.yticorientation.halign = 'right' self.yticorientation.height = 10 # Ticks table self.tictable = vcs.createtexttable() # parameters text settings self.parameterorientation = vcs.createtextorientation() self.parameterorientation.angle = 0 self.parameterorientation.halign = 'center' self.parameterorientation.height = 20 self.parametertable = vcs.createtexttable() # values in cell setting self.values = Values() # Defaults self.draw_mesh = 'y' self.missing_color = 3 self.xtic1 = Ys(None, None) self.xtic2 = Ys(None, None) self.ytic1 = Xs(None, None) self.ytic2 = Xs(None, None) # Set the logo textorientation self.logo = None # Set the time stamp time_stamp = vcs.createtext() time_stamp.height = 10 time_stamp.halign = 'center' time_stamp.path = 'right' time_stamp.valign = 'half' time_stamp.x = [0.9] time_stamp.y = [0.96] self.time_stamp = time_stamp
def __init__(self, interactor, label, dp, configurator): self.label = label self.display = dp super(LabelEditor, self).__init__(interactor, label, configurator) self.toolbar = vcs.vtk_ui.Toolbar( self.interactor, "%s Options" % label.member) template = vcs.gettemplate(dp.template) self.actor = get_actor(self.label, self.display) tprop = self.actor.GetTextProperty() self.real_bg = tprop.GetBackgroundColor() self.real_bg_opacity = tprop.GetBackgroundOpacity() tprop.SetBackgroundColor(contrasting_color(*tprop.GetColor())) tprop.SetBackgroundOpacity(.85) text_types_name = template.name + "_" + label.member try: self.tt = vcs.gettexttable(text_types_name) self.to = vcs.gettextorientation(text_types_name) except ValueError: self.tt = vcs.createtexttable(text_types_name, label.texttable) self.to = vcs.createtextorientation( text_types_name, label.textorientation) self.height_button = self.toolbar.add_slider_button( self.to.height, 1, 100, "Height", update=self.update_height) halign = self.toolbar.add_button( ["Left Align", "Center Align", "Right Align"], action=self.halign) valign = self.toolbar.add_button( ["Top Align", "Half Align", "Bottom Align"], action=self.valign) halign.set_state(self.to.halign) valign.set_state(__valign_map__[self.to.valign]) self.angle_button = self.toolbar.add_slider_button( self.to.angle, 0, 360, "Angle", update=self.update_angle) self.picker = None self.toolbar.add_button(["Change Color"], action=self.change_color) self.toolbar.show() self.label.texttable = self.tt.name self.label.textorientation = self.to.name
def __init__(self, interactor, label, dp, configurator): self.label = label self.display = dp super(LabelEditor, self).__init__(interactor, label, configurator) self.toolbar = vcs.vtk_ui.Toolbar(self.interactor, "%s Options" % label.member) template = vcs.gettemplate(dp.template) self.actor = get_actor(self.label, self.display) tprop = self.actor.GetTextProperty() self.real_bg = tprop.GetBackgroundColor() self.real_bg_opacity = tprop.GetBackgroundOpacity() tprop.SetBackgroundColor(contrasting_color(*tprop.GetColor())) tprop.SetBackgroundOpacity(.85) text_types_name = template.name + "_" + label.member try: self.tt = vcs.gettexttable(text_types_name) self.to = vcs.gettextorientation(text_types_name) except ValueError: self.tt = vcs.createtexttable(text_types_name, label.texttable) self.to = vcs.createtextorientation(text_types_name, label.textorientation) self.height_button = self.toolbar.add_slider_button( self.to.height, 1, 100, "Height", update=self.update_height) halign = self.toolbar.add_button( ["Left Align", "Center Align", "Right Align"], action=self.halign) valign = self.toolbar.add_button( ["Top Align", "Half Align", "Bottom Align"], action=self.valign) halign.set_state(self.to.halign) valign.set_state(__valign_map__[self.to.valign]) self.angle_button = self.toolbar.add_slider_button( self.to.angle, 0, 360, "Angle", update=self.update_angle) self.picker = None self.toolbar.add_button(["Change Color"], action=self.change_color) # Adds itself to self.toolbar automatically FontEditor(self.toolbar, self.set_font, current_font=vcs.getfontname(self.tt.font)) self.toolbar.show() self.label.texttable = self.tt.name self.label.textorientation = self.to.name
def diagnostics_template(): """creates and returns a VCS template suitable for diagnostics plots""" if 'diagnostic' in vcs.listelements('template'): tm = vcs.gettemplate('diagnostic') else: tm = vcs.createtemplate( 'diagnostic', 'default' ) # ...creates a template named 'diagnostic', as a copy of the one named 'default'. tm.title.x = 0.5 to = vcs.createtextorientation() to.halign = 'center' tm.title.textorientation = to tm.dataname.priority = 0 tm.units.priority = 0 return tm
def testVCSreset1only(self): for gtype in vcs.listelements(): b0 = vcs.listelements(gtype) if gtype == 'colormap': b = vcs.createcolormap() xtra = vcs.createisofill() untouched = vcs.listelements("isofill") elif gtype == "template": b = vcs.createtemplate() elif gtype == "textcombined": b = vcs.createtextcombined() elif gtype == "textorientation": b = vcs.createtextorientation() elif gtype == "texttable": b = vcs.createtexttable() elif gtype == "fillarea": b = vcs.createfillarea() elif gtype == "projection": b = vcs.createprojection() elif gtype == "marker": b = vcs.createmarker() elif gtype == "line": b = vcs.createline() elif gtype in ["display", "font", "fontNumber", "list", "format"]: vcs.manageElements.reset() continue else: b = vcs.creategraphicsmethod(gtype) if gtype != "colormap": xtra = vcs.createcolormap() untouched = vcs.listelements("colormap") b1 = vcs.listelements(gtype) self.assertNotEqual(b0, b1) vcs.manageElements.reset(gtype) b2 = vcs.listelements(gtype) self.assertEqual(b0, b2) if gtype == "colormap": self.assertEqual(untouched, vcs.listelements("isofill")) else: self.assertEqual(untouched, vcs.listelements("colormap")) vcs.manageElements.reset() if gtype == "colormap": self.assertNotEqual(untouched, vcs.listelements("isofill")) else: self.assertNotEqual(untouched, vcs.listelements("colormap")) # case for 1d weirdness sc = vcs.createscatter() vcs.manageElements.reset()
def setUp(self): f = cdms2.open(os.path.join(cdat_info.get_sampledata_path(), "clt.nc")) s = f("clt", slice(0, 1)) self.x = vcs.init(bg=True, geometry=(800, 600)) b = vcs.createboxfill() t = vcs.createtemplate() to = vcs.createtextorientation() to.angle = 90 t.xlabel1.textorientation = to b.xticlabels1 = {45: "45N"} b.datawc_x1 = -180 b.datawc_x2 = 180. self.b = b self.t = t self.x.plot(s, b, t) self.x.png("testClick") self.s = s
def __init__(self, interactor, label, dp, configurator): self.label = label self.display = dp super(LabelEditor, self).__init__(interactor, label, configurator) self.toolbar = vcs.vtk_ui.Toolbar(self.interactor, "%s Options" % label.member) template = vcs.gettemplate(dp.template) self.actor = get_actor(self.label, self.display) text_types_name = template.name + "_" + label.member try: self.tt = vcs.gettexttable(text_types_name) self.to = vcs.gettextorientation(text_types_name) except ValueError: self.tt = vcs.createtexttable(text_types_name, label.texttable) self.to = vcs.createtextorientation(text_types_name, label.textorientation) self.height_button = self.toolbar.add_slider_button( self.to.height, 1, 100, "Height", update=self.update_height) halign = self.toolbar.add_button( ["Left Align", "Center Align", "Right Align"], action=self.halign) valign = self.toolbar.add_button( ["Top Align", "Half Align", "Bottom Align"], action=self.valign) halign.set_state(self.to.halign) valign.set_state(__valign_map__[self.to.valign]) self.angle_button = self.toolbar.add_slider_button( self.to.angle, 0, 360, "Angle", update=self.update_angle) font_editor = FontEditor(self.toolbar, self.set_font, vcs.elements["fontNumber"][self.tt.font]) self.picker = None self.toolbar.add_button(["Change Color"], action=self.change_color) self.toolbar.show() self.label.texttable = self.tt.name self.label.textorientation = self.to.name
def test_pcoord(self): import vcs import vcsaddons J=self.loadJSON() rms_xyt = J(statistic=["rms_xyt"],season=["ann"],region="global")(squeeze=1) gm = vcsaddons.createparallelcoordinates(x=self.x) t = vcs.createtemplate() to = vcs.createtextorientation() to.angle=-45 to.halign="right" t.xlabel1.textorientation = to.name t.data.list() t.reset('x',0.05,0.9,t.data.x1,t.data.x2) t.data.list() #t.reset('y',0.5,0.9,t.data.y1,t.data.y2) ln = vcs.createline() ln.color = [[0,0,0,0]] t.legend.line = ln t.box1.priority=0 t.legend.x1 = .91 t.legend.x2 = .99 t.legend.y1 = t.data.y1 t.legend.y2 = t.data.y2 # Set variable name rms_xyt.id = "RMS" # Set units of each variables on axis rms_xyt.getAxis(-2).units = ["mm/day","mm/day","hPa","W/m2","W/m2","W/m2", "K","K","K","m/s","m/s","m/s","m/s","m"] # Sets title rms_xyt.title = "Annual Mean Error" gm.plot(rms_xyt,template=t) fnm = os.path.join(os.getcwd(), "testParallelCoordinates.png") self.checkImage(fnm)
def __init__(self, interactor, label, dp, configurator): self.label = label self.display = dp super(LabelEditor, self).__init__(interactor, label, configurator) self.toolbar = vcs.vtk_ui.Toolbar(self.interactor, "%s Options" % label.member) template = vcs.gettemplate(dp.template) self.actor = get_actor(self.label, self.display) text_types_name = template.name + "_" + label.member try: self.tt = vcs.gettexttable(text_types_name) self.to = vcs.gettextorientation(text_types_name) except ValueError: self.tt = vcs.createtexttable(text_types_name, label.texttable) self.to = vcs.createtextorientation(text_types_name, label.textorientation) self.height_button = self.toolbar.add_slider_button(self.to.height, 1, 100, "Height", update=self.update_height) halign = self.toolbar.add_button(["Left Align", "Center Align", "Right Align"], action=self.halign) valign = self.toolbar.add_button(["Top Align", "Half Align", "Bottom Align"], action=self.valign) halign.set_state(self.to.halign) valign.set_state(__valign_map__[self.to.valign]) self.angle_button = self.toolbar.add_slider_button(self.to.angle, 0, 360, "Angle", update=self.update_angle) font_editor = FontEditor(self.toolbar, self.set_font, vcs.elements["fontNumber"][self.tt.font]) self.picker = None self.toolbar.add_button(["Change Color"], action=self.change_color) self.toolbar.show() self.label.texttable = self.tt.name self.label.textorientation = self.to.name
def plot_portrait( stat_xy, # array to visualize imgName='portrait_plot', # file name plotTitle=None, # title string on top img_length=800, img_height=600, # image size in pixel colormap='viridis', clevels=None, ccolors=None, # colormap and levels xtic_textsize=None, ytic_textsize=None, # font size for axes tic labels parea=None, # plotting area in ratio, in purpose of margin control missing_color='black', # color for missing data box Annotate=False, stat_xy_annotate=None, # annotation (showing value number in each box) num_box_partitioning=1, stat_xy_2=None, stat_xy_3=None, stat_xy_4=None, # additional triangle logo=True, GridMeshLine=True, # miscellaneous ): """ NOTE: Input - stat_xy: cdms2 MV2 2D array with proper axes decorated, values to visualize. - imgName: string, file name for PNG image file (e.g., 'YOUR_PLOT.png' or 'YOUR_PLOT'. If .png is not included, it will be added, so no worry). - plotTilte: string - img_length: integer, pixels for image file length. default=800. - img_height: integer, pixels for image file height. default=600. - colormap: string or actual VCS colormap. Default is 'viridis' that is default in VCS. - clevels: list of numbers (int or float). Colorbar levels. If not given automatically generated. - ccolors: list of colors. If not given automatically generate. - xtic_textsize: int, size of text for x-axis tic. If not given automatically generated. - ytic_textsize: int, size of text for y-axis tic. If not given automatically generated. - parea: list or tuple of float numbers between 0 to 1. Plotting area: (x1, x2, y1, y2). If not given automatically placed. - missing_color: string or color code (tuple or list of R, G, B, alpha). Color for missing data box. Default is 'black' - Annotate: bool, default=False. If Annotate, show numbers in individual boxes. - stat_xy_annotate: cdms2 MV2 2D array with proper axes decorated. Only needed when number to show as value annotated is not corresponding to the colormap. Not even bother when Annotate=False. For example, color for values those normalized by median, while annotate actual value for metrics. - num_box_partitioning: integer. How many partitioning in a box? e.g., 4: 4 triangles in each box. Default=1, should be less equal than 4. - stat_xy_2: cdms2 MV2 2D array. Stat for 2nd triangle in box. Default=None - stat_xy_3: cdms2 MV2 2D array. Stat for 3rd triangle in box. Default=None - stat_xy_4: cdms2 MV2 2D array. Stat for 4th triangle in box. Default=None - logo: bool, default=True. If False, CDAT logo turned off - GridMeshLine: bool, default=True. If False, no lines for boundary of individual boxes Output - PNG image file """ # VCS Canvas x = vcs.init(bg=True, geometry=(img_length, img_height)) # CDAT logo control if not logo: x.drawlogooff() # Set up Portrait Plot """ If you are NOT using JUPYTER NOTEBOOK, it is okay to DEACTIVATE below line and ACTIVATE second below line, and skip the "Prepare the Notebook" part above. """ #P = PortraitNotebook(x) P = pcmdi_metrics.graphics.portraits.Portrait() # # Preprocessing step to "decorate" the axis # axes = stat_xy.getAxisList() xax = [t + ' ' for t in list(axes[1][:])] yax = [t + ' ' for t in list(axes[0][:])] P.decorate(stat_xy, yax, xax) # # Customize # SET = P.PLOT_SETTINGS # Viewport on the Canvas if parea is not None: SET.x1, SET.x2, SET.y1, SET.y2 = parea # Both X (horizontal) and y (VERTICAL) ticks # Text table SET.tictable = vcs.createtexttable() SET.tictable.color = "black" # X (bottom) ticks # Text Orientation SET.xticorientation = vcs.createtextorientation() SET.xticorientation.angle = -90 SET.xticorientation.halign = "right" if xtic_textsize: SET.xticorientation.height = xtic_textsize # Y (vertical) ticks SET.yticorientation = vcs.createtextorientation() SET.yticorientation.angle = 0 SET.yticorientation.halign = "right" if ytic_textsize: SET.yticorientation.height = ytic_textsize # We can turn off the "grid" if needed if GridMeshLine: SET.draw_mesh = "y" else: SET.draw_mesh = "n" # Color for missing data SET.missing_color = missing_color # Timestamp SET.time_stamp = None # Colormap SET.colormap = colormap if clevels: SET.levels = clevels if ccolors: SET.fillareacolors = ccolors # Annotated Plot (i.e. show value number in boxes) if Annotate: SET.values.show = True if stat_xy_annotate is None: SET.values.array = stat_xy else: SET.values.array = stat_xy_annotate # Check before plotting if num_box_partitioning > 4: sys.exit('ERROR: num_box_partitioning should be less equal than 4') # # Plot # P.plot(stat_xy, multiple=pp_multiple(1, num_box_partitioning), x=x) # Add triangles if needed # Decorate additional arrays with empty string axes to avoid overwriting same information (if not, font will look ugly) xax_empty = [' ' for t in stat_xy.getAxis(1)[:]] yax_empty = [' ' for t in stat_xy.getAxis(0)[:]] if stat_xy_2 is not None: P.decorate(stat_xy_2, yax_empty, xax_empty) P.plot(stat_xy_2, x=x, multiple=pp_multiple(2, num_box_partitioning)) if stat_xy_3 is not None: P.decorate(stat_xy_3, yax_empty, xax_empty) P.plot(stat_xy_3, x=x, multiple=pp_multiple(3, num_box_partitioning)) if stat_xy_4 is not None: P.decorate(stat_xy_4, yax_empty, xax_empty) P.plot(stat_xy_4, x=x, multiple=pp_multiple(4, num_box_partitioning)) # Plot title if plotTitle: plot_title = vcs.createtext() plot_title.x = .5 plot_title.y = (SET.y2 + 1) / 2. plot_title.height = 30 plot_title.halign = 'center' plot_title.valign = 'half' plot_title.color = 'black' plot_title.string = plotTitle x.plot(plot_title) # Save if imgName.split('.')[-1] not in ['PNG', 'png']: imgName = imgName + '.png' x.png(imgName) # Preserve original axes stat_xy.setAxisList(axes) return P
def init_polar(): # Create nice polar template try: t = vcs.createtemplate("polar_oned") t.data.x1 = .2 t.data.x2 = .8 t.data.y1 = .2 t.data.y2 = .8 t.legend.x1 = .85 t.legend.x2 = 1 t.legend.y1 = .15 t.legend.y2 = .85 dash = vcs.createline() dash.type = "dash" dot = vcs.createline() dot.type = "dot" t.xtic1.line = dash t.ytic1.line = dot left_aligned = vcs.createtextorientation() left_aligned.halign = "left" left_aligned.valign = "half" t.legend.textorientation = left_aligned except vcs.vcsError: # Template already exists pass # Create some nice default polar GMs degree_polar = polar.Gpo("degrees", template="polar_oned") degree_polar.datawc_x1 = 0 degree_polar.datawc_x2 = 360 degree_polar.xticlabels1 = { i: str(i) for i in range(0, 360, 45) } clock_24 = polar.Gpo("diurnal", template="polar_oned") clock_24.datawc_x1 = 0 clock_24.datawc_x2 = 24 clock_24.clockwise = True # 6 AM on the right clock_24.theta_offset = -6 clock_24.xticlabels1 = { i: str(i) for i in range(0, 24, 3) } clock_24_meridiem = polar.Gpo("diurnal_12_hour", source="diurnal", template="polar_oned") clock_24_meridiem.xticlabels1 = { 0: "12 AM", 3: "3 AM", 6: "6 AM", 9: "9 AM", 12: "12 PM", 15: "3 PM", 18: "6 PM", 21: "9 PM" } clock_12 = polar.Gpo("semidiurnal", source="diurnal", template="polar_oned") clock_12.datawc_x2 = 12 clock_12.xticlabels1 = { i: str(i) for i in range(3, 13, 3) } # 3 on the right clock_12.theta_offset = -3 annual_cycle = polar.Gpo("annual_cycle", template="polar_oned") annual_cycle.datawc_x1 = 1 annual_cycle.datawc_x2 = 13 annual_cycle.clockwise = True annual_cycle.xticlabels1 = { 1: "Jan", 2: "Feb", 3: "Mar", 4: "Apr", 5: "May", 6: "Jun", 7: "Jul", 8: "Aug", 9: "Sep", 10: "Oct", 11: "Nov", 12: "Dec" } # Put December on the top annual_cycle.theta_offset = -2 seasonal = polar.Gpo("seasonal", template="polar_oned") seasonal.datawc_x1 = 0 seasonal.datawc_x2 = 4 seasonal.xticlabels1 = {0: "DJF", 1: "MAM", 2: "JJA", 3: "SON"} seasonal.clockwise = True # DJF on top seasonal.theta_offset = -1
def generateTemplate(self): template = vcs.createtemplate() # Now sets all the things for the template... # Sets a bunch of template attributes to off for att in [ 'line1', 'line2', 'line3', 'line4', 'box2', 'box3', 'box4', 'min', 'max', 'mean', 'xtic1', 'xtic2', 'ytic1', 'ytic2', 'xvalue', 'yvalue', 'zvalue', 'tvalue', 'xunits', 'yunits', 'zunits', 'tunits', 'source', 'title', 'dataname', ]: a = getattr(template, att) setattr(a, 'priority', 0) for att in [ 'xname', 'yname', ]: a = getattr(template, att) setattr(a, 'priority', 0) template.data.x1 = self.PLOT_SETTINGS.x1 template.data.x2 = self.PLOT_SETTINGS.x2 template.data.y1 = self.PLOT_SETTINGS.y1 template.data.y2 = self.PLOT_SETTINGS.y2 template.box1.x1 = self.PLOT_SETTINGS.x1 template.box1.x2 = self.PLOT_SETTINGS.x2 template.box1.y1 = self.PLOT_SETTINGS.y1 template.box1.y2 = self.PLOT_SETTINGS.y2 template.xname.y = self.PLOT_SETTINGS.y2 + .02 template.yname.x = self.PLOT_SETTINGS.x2 + .01 template.xlabel1.y = self.PLOT_SETTINGS.y1 template.xlabel2.y = self.PLOT_SETTINGS.y2 template.xlabel1.texttable = self.PLOT_SETTINGS.tictable template.xlabel2.texttable = self.PLOT_SETTINGS.tictable template.xlabel1.textorientation = \ self.PLOT_SETTINGS.xticorientation template.xlabel2.textorientation = \ self.PLOT_SETTINGS.xticorientation template.ylabel1.x = self.PLOT_SETTINGS.x1 template.ylabel2.x = self.PLOT_SETTINGS.x2 template.ylabel1.texttable = self.PLOT_SETTINGS.tictable template.ylabel2.texttable = self.PLOT_SETTINGS.tictable template.ylabel1.textorientation = \ self.PLOT_SETTINGS.yticorientation template.ylabel2.textorientation = \ self.PLOT_SETTINGS.yticorientation if self.PLOT_SETTINGS.xtic1.y1 is not None: template.xtic1.y1 = self.PLOT_SETTINGS.xtic1.y1 template.xtic1.priority = 1 if self.PLOT_SETTINGS.xtic1.y2 is not None: template.xtic1.y2 = self.PLOT_SETTINGS.xtic1.y2 template.xtic1.priority = 1 if self.PLOT_SETTINGS.xtic2.y1 is not None: template.xtic2.y1 = self.PLOT_SETTINGS.xtic2.y1 template.xtic2.priority = 1 if self.PLOT_SETTINGS.xtic2.y2 is not None: template.xtic2.y2 = self.PLOT_SETTINGS.xtic2.y2 template.xtic2.priority = 1 if self.PLOT_SETTINGS.ytic1.x1 is not None: template.ytic1.x1 = self.PLOT_SETTINGS.ytic1.x1 template.ytic1.priority = 1 if self.PLOT_SETTINGS.ytic1.x2 is not None: template.ytic1.x2 = self.PLOT_SETTINGS.ytic1.x2 template.ytic1.priority = 1 if self.PLOT_SETTINGS.ytic2.x1 is not None: template.ytic2.priority = 1 template.ytic2.x1 = self.PLOT_SETTINGS.ytic2.x1 if self.PLOT_SETTINGS.ytic2.x2 is not None: template.ytic2.priority = 1 template.ytic2.x2 = self.PLOT_SETTINGS.ytic2.x2 template.legend.x1 = self.PLOT_SETTINGS.legend.x1 template.legend.x2 = self.PLOT_SETTINGS.legend.x2 template.legend.y1 = self.PLOT_SETTINGS.legend.y1 template.legend.y2 = self.PLOT_SETTINGS.legend.y2 try: tmp = vcs.createtextorientation('crap22') except Exception: tmp = vcs.gettextorientation('crap22') tmp.height = 12 # tmp.halign = 'center' # template.legend.texttable = tmp template.legend.textorientation = tmp return template
def init_polar(): # Create nice polar template try: t = vcs.createtemplate("polar_oned") t.data.x1 = .2 t.data.x2 = .8 t.data.y1 = .2 t.data.y2 = .8 t.legend.x1 = .85 t.legend.x2 = 1 t.legend.y1 = .15 t.legend.y2 = .85 dash = vcs.createline() dash.type = "dash" dot = vcs.createline() dot.type = "dot" t.xtic1.line = dash t.ytic1.line = dot left_aligned = vcs.createtextorientation() left_aligned.halign = "left" left_aligned.valign = "half" t.legend.textorientation = left_aligned except vcs.vcsError: # Template already exists pass # Create some nice default polar GMs degree_polar = Gpo("degrees", template="polar_oned") degree_polar.negative_magnitude = True degree_polar.datawc_x1 = 0 degree_polar.datawc_x2 = 360 degree_polar.xticlabels1 = {i: str(i) for i in range(0, 360, 45)} clock_24 = Gpo("diurnal", template="polar_oned") clock_24.negative_magnitude = True clock_24.datawc_x1 = 0 clock_24.datawc_x2 = 24 clock_24.clockwise = True # 6 AM on the right clock_24.theta_offset = -6 clock_24.xticlabels1 = {i: str(i) for i in range(0, 24, 3)} clock_24_meridiem = Gpo("diurnal_12_hour", source="diurnal", template="polar_oned") clock_24_meridiem.xticlabels1 = { 0: "12 AM", 3: "3 AM", 6: "6 AM", 9: "9 AM", 12: "12 PM", 15: "3 PM", 18: "6 PM", 21: "9 PM" } clock_12 = Gpo("semidiurnal", source="diurnal", template="polar_oned") clock_12.negative_magnitude = True clock_12.datawc_x2 = 12 clock_12.xticlabels1 = {i: str(i) for i in range(3, 13, 3)} # 3 on the right clock_12.theta_offset = -3 annual_cycle = Gpo("annual_cycle", template="polar_oned") annual_cycle.negative_magnitude = True annual_cycle.datawc_x1 = 1 annual_cycle.datawc_x2 = 13 annual_cycle.clockwise = True annual_cycle.xticlabels1 = { 1: "Jan", 2: "Feb", 3: "Mar", 4: "Apr", 5: "May", 6: "Jun", 7: "Jul", 8: "Aug", 9: "Sep", 10: "Oct", 11: "Nov", 12: "Dec" } # Put December on the top annual_cycle.theta_offset = -2 seasonal = Gpo("seasonal", template="polar_oned") seasonal.negative_magnitude = True seasonal.datawc_x1 = 0 seasonal.datawc_x2 = 4 seasonal.xticlabels1 = {0: "DJF", 1: "MAM", 2: "JJA", 3: "SON"} seasonal.clockwise = True # DJF on top seasonal.theta_offset = -1
# Create a base template and place all of the labels that we want root_template = vcs.createtemplate("reduced") root_template.blank(["mean", "max", "min", "zvalue", "dataname", "crtime", "ytic2", "xtic2"]) # Shrink data and box1 a little horizontally root_template.data.x2 -= .05 root_template.box1.x2 -= .05 # Move the legend to the right side root_template.legend.x1 = root_template.data.x2 + .01 root_template.legend.x2 = root_template.data.x2 + .03 root_template.legend.y1 = root_template.data.y1 root_template.legend.y2 = root_template.data.y2 # Create a left/top aligned textorientation for the labels textorientation = vcs.createtextorientation() textorientation.halign = 'left' textorientation.valign = 'half' root_template.legend.textorientation = textorientation.name # Align title and units to the left side of the data root_template.title.x = root_template.data.x1 root_template.units.x = root_template.title.x root_template.units.y = root_template.title.y - .03 root_template.crdate.x = root_template.data.x2 right_align = vcs.createtextorientation() right_align.halign = "right" root_template.crdate.textorientation = right_align # Template Construction
def build_templates(canvas=None, graphicMethodStrings=None, overlay=None, rows=1, columns=1, mainTemplateOptions=None, templateOptionsArray=None, templateNameArray=None, legendDirection='vertical', forceAspectRatio=False, onlyData=False, disableLegend=False): """ This function generates and adjusts the templates needed to plot the diagnostic plots. """ #debug: # debugInfoFunc(graphicMethodStrings, overlay, rows, columns, # mainTemplateOptions, templateOptionsArray, templateNameArray, # legendDirection, forceAspectRatio, onlyData) if rows == 0 or columns == 0: raise ValueError( "One must enter a size bigger than zero for rows and columns.") exit(0) if ((graphicMethodStrings == None) or (mainTemplateOptions == None)) or ((overlay == None) or (canvas == None)): return (None, None) graphicMethodObjects = [] for i in range( len(graphicMethodStrings)): # make sure the graphics method exists if (graphicMethodStrings[i] == 'isofill') and ('uvwg' not in canvas.listelements('isofill')): graphicMethodObjects.append( canvas.createisofill('uvwg_' + (str(random.random())[2:]), 'default')) if (graphicMethodStrings[i] == 'isoline') and ('uvwg' not in canvas.listelements('isoline')): graphicMethodObjects.append( canvas.createisoline('uvwg_' + (str(random.random())[2:]), 'default')) if (graphicMethodStrings[i] == 'boxfill') and ('uvwg' not in canvas.listelements('boxfill')): graphicMethodObjects.append( canvas.createisoline('uvwg_' + (str(random.random())[2:]), 'default')) if (graphicMethodStrings[i] == 'yxvsx') and ('uvwg' not in canvas.listelements('yxvsx')): graphicMethodObjects.append( canvas.createyxvsx('uvwg_' + (str(random.random())[2:]), 'default')) if overlay[i] == 0: graphicMethodObjects[i].linewidth = 1.5 else: graphicMethodObjects[i].linewidth = 2.0 graphicMethodObjects[i].line = 'dash' graphicMethodObjects[i].linecolor = 242 if (graphicMethodStrings[i] == 'vector') and ('uvwg' not in canvas.listelements('vector')): graphicMethodObjects.append( canvas.createvector('uvwg_' + (str(random.random())[2:]), 'default')) if (graphicMethodStrings[i] == 'scatter') and ('uvwg' not in canvas.listelements('scatter')): graphicMethodObjects.append( canvas.createscatter('uvwg_' + (str(random.random())[2:]), 'default')) if overlay[i] == 0: graphicMethodObjects[i].markersize = 8 else: graphicMethodObjects[i].linewidth = 2.0 graphicMethodObjects[i].linecolor = 242 graphicMethodObjects[i].markersize = 1 if (graphicMethodStrings[i] == 'taylordiagram'): td = canvas.createtaylordiagram( 'taylor_' + (str(random.random())[2:]), 'default') graphicMethodObjects.append(td) #graphicMethodObjects[i].addMarker() #graphicMethodObjects[i].Marker.size = 8 # if rows > columns: # canvas.portrait() # else: # canvas.landscape() # Creates EzTemplate M = EzTemplate.Multi(rows=rows, columns=columns) # Set EzTemplate Options M.legend.direction = legendDirection # default='horizontal' # Font size auto-scale scaleFactor = gaussian(float(max(rows, columns)) / 10.0, 0.1, 0.45) # Title size auto-scale if (rows == columns) and (rows == 1): titleScaleFactor = 1.3 * scaleFactor else: titleScaleFactor = linear(float(max(rows, columns))) # Get from yxvsx_merra_tas.py # Set conversion factor to multiply font height coordinates by # to obtain the value in normalized coordinates. This is set # by trial-and-error: fontht2norm = 0.0007 dx = calcdx(M, rows, columns) dy = calcdy(M, rows, columns) # Aspect Ratio: if forceAspectRatio: if dx > 2 * dy: while calcdx(M, rows, columns) > 2 * dy: M.margins.left += 0.01 M.margins.right += 0.01 elif 2 * dy > dx: while 2 * calcdy(M, rows, columns) > dx: M.margins.top += 0.01 M.margins.bottom += 0.01 # Adjusts margins and vertical spaces to # handle title-data or title-(out of box) problems if mainTemplateOptions.title: y1_row0 = calcy1(M, 0, dy, 0.0) y1_row1 = calcy1(M, 1, dy, 0.0) y2_row1 = calcy2(y1_row1, dy, 0.0) title_height = 14 * fontht2norm # 14 is the default font size if rows > 1: Mt = EzTemplate.Multi(rows=rows, columns=columns, legend_direction=legendDirection) Mt.margins = M.margins Mt.spacing = M.spacing # Avoiding overlay of titles and xnames: templateAbove = Mt.get(row=0, column=0, legend='local', font=False) templateBelow = Mt.get(row=1, column=0, legend='local', font=False) titleBelowY2 = title_height + templateBelow.title.y while titleBelowY2 > templateAbove.xname.y: Mt.spacing.vertical += 0.01 templateBelow = Mt.get(row=1, column=0, legend='local', font=False) templateAbove = Mt.get(row=0, column=0, legend='local', font=False) titleBelowY2 = title_height + templateBelow.title.y # Avoiding titles out of bounds titleAboveY2 = title_height + templateAbove.title.y while titleAboveY2 > 1.0: Mt.margins.top += 0.01 Mt.margins.bottom += 0.01 templateAbove = Mt.get(row=0, column=0, legend='local') titleAboveY2 = title_height + templateAbove.title.y M.spacing = Mt.spacing M.margins = Mt.margins elif rows == 1: title_height = 60 * fontht2norm # one plot per page has a different scale Mt = EzTemplate.Multi(rows=rows, columns=columns) Mt.margins = M.margins Mt.spacing = M.spacing tt = Mt.get(row=0, column=0, legend='local') tt.scalefont(scaleFactor) titley2 = title_height * scaleFactor + tt.title.y # Avoiding titles out of bounds while titley2 > 1.0: Mt.margins.top += 0.01 Mt.margins.bottom += 0.01 tt = Mt.get(row=0, column=0, legend='local') titley2 = title_height * scaleFactor + tt.title.y M.margins = Mt.margins M.spacing = Mt.spacing # Adjusts the Xname position related to out of page problems if mainTemplateOptions.xname: Mt = EzTemplate.Multi(rows=rows, columns=columns, legend_direction=legendDirection) Mt.margins = M.margins Mt.spacing = M.spacing tt = None if rows > 1: tt = Mt.get(row=rows - 1, column=0, legend='local') else: tt = Mt.get(row=0, column=0, legend='local') xnameY = tt.xname.y # 0.004 was found by trying-error procedure while xnameY < 0.004: Mt.margins.top += 0.01 Mt.margins.bottom += 0.01 if rows > 1: tt = Mt.get(row=rows - 1, column=0, legend='local') else: tt = Mt.get(row=0, column=0, legend='local') xnameY = tt.xname.y #print "xnameY = ", xnameY M.margins.top = Mt.margins.top M.margins.bottom = Mt.margins.bottom # Adjust the xname position related to other plots in the same page if mainTemplateOptions.xname: y1_row0 = calcy1(M, 0, dy, 0.0) y1_row1 = calcy1(M, 1, dy, 0.0) y2_row1 = calcy2(y1_row1, dy, 0.0) if rows > 1: Mt = EzTemplate.Multi(rows=rows, columns=columns, legend_direction=legendDirection) Mt.margins.top = M.margins.top Mt.margins.bottom = M.margins.bottom Mt.spacing.vertical = M.spacing.vertical Mt.spacing.horizontal = M.spacing.horizontal tt = Mt.get(row=0, column=0, legend='local') xnameY = tt.xname.y # Avoiding overlay of xnames and data while xnameY < (y2_row1 + 0.01 * y2_row1): Mt.spacing.vertical += 0.01 dy = calcdy(Mt, rows, columns) y1_row1 = calcy1(Mt, 1, dy, 0.0) y2_row1 = calcy2(y1_row1, dy, 0.0) #print "dy = {0}, y1_row1 = {1}, y2_row1 = {2}".format(dy, y1_row1, y2_row1) M.spacing.vertical = Mt.spacing.vertical # Adjusts the Ylabel1 position related to out of page problems if mainTemplateOptions.ylabel1: Mt = EzTemplate.Multi(rows=rows, columns=columns, legend_direction=legendDirection) Mt.margins = M.margins Mt.spacing = M.spacing tt = Mt.get(row=0, column=0, legend='local', font=False) ylabel1X = tt.ylabel1.x while ylabel1X < 0.0: Mt.margins.left += 0.01 Mt.margins.right += 0.01 tt = Mt.get(row=0, column=0, legend='local') ylabel1X = tt.ylabel1.x M.margins = Mt.margins M.spacing = Mt.spacing # Adjusts the Yname position related to out of page problems # if mainTemplateOptions.yname: # Mt = EzTemplate.Multi(rows=rows, columns=columns, legend_direction=legendDirection) # Mt.legend.direction = legendDirection # Mt.margins = M.margins # Mt.spacing = M.spacing # tt = Mt.get(row=0, column=0, legend='local') # ynamex = tt.yname.x # while ynamex < 0.0: # Mt.margins.left *= 1.01 # Mt.margins.right *= 1.01 # tt = Mt.get(row=0, column=0, legend='local') # ynamex = tt.yname.x # M.margins.left = Mt.margins.left # M.margins.right = Mt.margins.right # Adjusts yname position related to the page margins if mainTemplateOptions.yname: Mt = EzTemplate.Multi(rows=rows, columns=columns, legend_direction=legendDirection) Mt.spacing = M.spacing Mt.margins = M.margins tt = Mt.get(row=0, column=0, legend='local', font=False) while tt.yname.x < 0.0015: Mt.margins.left += 0.05 tt = Mt.get(row=0, column=0, legend='local', font=False) M.margins = Mt.margins M.spacing = Mt.spacing # Adjusts the Yname position related to other plots in the same page if mainTemplateOptions.yname and (columns > 1): Mt = EzTemplate.Multi(rows=rows, columns=columns, legend_direction=legendDirection) Mt.legend.direction = legendDirection Mt.margins = M.margins Mt.spacing = M.spacing tt = Mt.get(row=0, column=0, legend='local') # takes legend changes in effect... delta = float(tt.data.x2 - tt.data.x1) posx2 = tt.legend.x1 + 0.09 * delta if posx2 > 1.0: posx2 = tt.legend.x1 + 0.05 * delta legendx2 = posx2 tt2 = Mt.get(row=0, column=1, legend='local') ynamex = tt2.yname.x while ynamex < legendx2: Mt.spacing.horizontal += 0.01 tt = Mt.get(row=0, column=0, legend='local') # takes legend changes in effect... delta = float(tt.data.x2 - tt.data.x1) posx2 = tt.legend.x1 + 0.09 * delta if posx2 > 1.0: posx2 = tt.legend.x1 + 0.05 * delta legendx2 = posx2 tt2 = Mt.get(row=0, column=1, legend='local') ynamex = tt2.yname.x #M.spacing.horizontal = Mt.spacing.horizontal M.margins = Mt.margins M.spacing = Mt.spacing # Adjusts legend position if mainTemplateOptions.legend: Mt = EzTemplate.Multi(rows=rows, columns=columns, legend_direction=legendDirection) Mt.legend.direction = legendDirection Mt.margins = M.margins Mt.spacing = M.spacing tt = Mt.get(row=0, column=0, legend='local', font=False) # takes legend changes in effect... delta = float(tt.data.x2 - tt.data.x1) if legendDirection == 'vertical': posx2 = tt.legend.x1 + 0.09 * delta if posx2 > 1.0: posx2 = tt.legend.x1 + 0.05 * delta legendx2 = posx2 while legendx2 > 0.96: Mt.margins.left += 0.02 Mt.margins.right += 0.02 tt = Mt.get(row=0, column=0, legend='local', font=False) # takes legend changes in effect... delta = float(tt.data.x2 - tt.data.x1) posx2 = tt.legend.x1 + 0.09 * delta if posx2 > 1.0: posx2 = tt.legend.x1 + 0.06 * delta legendx2 = posx2 elif legendDirection == 'horizontal': # Fix bug where ynames and values are out of bound in display but not in value. Mt.margins.left += 0.025 while tt.ylabel1.x < 0.0015: Mt.margins.left += 0.1 tt = Mt.get(row=0, column=0, legend='local', font=False) M.margins.left = Mt.margins.left M.margins.right = Mt.margins.right # Adjusts vertical spacing if Mean is enabled and the aspect-ration is being forced: if mainTemplateOptions.mean and forceAspectRatio: Mt = EzTemplate.Multi(rows=rows, columns=columns, legend_direction=legendDirection) Mt.margins.top = M.margins.top Mt.margins.bottom = M.margins.bottom Mt.spacing.vertical = M.spacing.vertical Mt.spacing.horizontal = M.spacing.horizontal tt = Mt.get(row=0, column=0, legend='local') tt.scalefont(scaleFactor) tt.mean.x = tt.title.x mean_orientation = vcs.gettextorientation(tt.mean.textorientation) mean_orientation.halign = "center" mean_orientation.valign = "top" mean_orientation.height *= scaleFactor * 0.7 tt.mean.textorientation = mean_orientation # 0.009 was found empirically if math.fabs(tt.mean.y - tt.data.y2) < 0.009: while math.fabs(tt.mean.y - tt.data.y2) < 0.009: Mt.margins.top += 0.01 Mt.margins.bottom += 0.01 tt = Mt.get(row=0, column=0, legend='local') tt.scalefont(scaleFactor) M.margins.top = Mt.margins.top M.margins.bottom = Mt.margins.bottom ###################### # Generating Templates finalTemplates = [] for i in range(len(graphicMethodStrings)): if (len(overlay) > 1) and (overlay[i] == 1): lastTemplate = finalTemplates[-1] cpLastTemplate = canvas.createtemplate( lastTemplate.name + '_overlay', lastTemplate.name) # Avoiding legend overlaping. cpLastTemplate.legend.y1 += 0.01 setTemplateOptions(cpLastTemplate, templateOptionsArray[i]) finalTemplates.append(cpLastTemplate) continue # Template name #if (templateNameArray is not None) and (len(templateNameArray) > i): # M.template = templateNameArray[i] # Legend into plot area template = M.get(legend='local') # scale fonts template.scalefont(scaleFactor) if mainTemplateOptions.title: # Align title delta = template.data.x2 - template.data.x1 template.title.x = template.data.x1 + float(delta) / 2.0 if rows == 1: template.title.y *= 0.99 title_orientation = vcs.createtextorientation() title_orientation.halign = "center" title_orientation.height *= titleScaleFactor # 100 * deltaY # default = 14 template.title.textorientation = title_orientation if mainTemplateOptions.dataname: template.dataname.x = template.data.x1 template.dataname.y = template.data.y2 + 0.01 dataname_orientation = vcs.gettextorientation( template.dataname.textorientation) dataname_orientation.height *= 0.98 template.dataname.textorientation = dataname_orientation if mainTemplateOptions.legend: if legendDirection == 'vertical': # Adjusting legend position delta = template.data.x2 - template.data.x1 posx2 = template.legend.x1 + 0.08 * delta if posx2 > 1.0: posx2 = template.legend.x1 + 0.05 * delta template.legend.x2 = posx2 elif legendDirection == 'horizontal': # Adjusting legend position template.legend.x1 = template.data.x1 template.legend.x2 = template.data.x2 deltaL = template.legend.y2 - template.legend.y1 template.legend.y2 = template.xname.y - 0.03 template.legend.y1 = template.legend.y2 - deltaL - 0.01 if mainTemplateOptions.mean: # Align Mean template.mean.x = template.title.x if rows == 1: template.mean.y *= 0.99 mean_orientation = vcs.createtextorientation() mean_orientation.halign = "center" #mean_orientation.valign = "top" if (rows == columns) and (rows == 1): mean_orientation.height *= scaleFactor * 0.88 else: mean_orientation.height *= scaleFactor * 0.65 template.mean.textorientation = mean_orientation if mainTemplateOptions.xname: #template.xname.y *= 1.01 xname_orientation = vcs.gettextorientation( template.xname.textorientation) xname_orientation.halign = "center" #xname_orientation.valign = "bottom" xname_orientation.height *= 0.85 template.xname.textorientation = xname_orientation if mainTemplateOptions.yname: #template.yname.y *= 1.01 yname_orientation = vcs.gettextorientation( template.yname.textorientation) yname_orientation.halign = "center" #yname_orientation.valign = "top" yname_orientation.height *= 0.85 template.yname.textorientation = yname_orientation if mainTemplateOptions.xlabel1: #template.xlabel1.y *= 1.01 xlabel1_orientation = vcs.gettextorientation( template.xlabel1.textorientation) #xlabel1_orientation.halign = "center" #xlabel1_orientation.valign = "bottom" xlabel1_orientation.height *= 0.85 template.xlabel1.textorientation = xlabel1_orientation if mainTemplateOptions.ylabel1: #template.ylabel1.y *= 1.01 ylabel1_orientation = vcs.gettextorientation( template.ylabel1.textorientation) #ylabel1_orientation.halign = "center" #ylabel1_orientation.valign = "bottom" ylabel1_orientation.height *= 0.85 template.ylabel1.textorientation = ylabel1_orientation if mainTemplateOptions.units: template.units.x = template.data.x2 - (5 * 14 * fontht2norm ) # 5 charactes if mainTemplateOptions.mean: template.units.y = template.mean.y else: template.units.y = template.data.y2 + 0.01 units_orientation = vcs.gettextorientation( template.units.textorientation) units_orientation.halign = "left" #units_orientation.valign = "bottom" units_orientation.height *= 0.85 template.units.textorientation = units_orientation if mainTemplateOptions.min: template.min.x = template.legend.x1 if mainTemplateOptions.max: minTo = canvas.gettextorientation(template.min.textorientation) minheight = minTo.height * fontht2norm template.max.x = template.legend.x1 if (rows == columns) and (rows == 1): template.max.y = template.min.y - 1.55 * minheight else: template.max.y = template.min.y - 1.35 * minheight if onlyData: dudTemplate = TemplateOptions() dudTemplate.setAllFalse() dudTemplate.data = True setTemplateOptions(template, dudTemplate) else: if (templateOptionsArray is not None) and (len(templateOptionsArray) > i): setTemplateOptions(template, templateOptionsArray[i]) else: setTemplateOptions(template, mainTemplateOptions) if disableLegend == True: template.legend.priority = 0 finalTemplates.append(template) return (graphicMethodObjects, finalTemplates)
def generate_portrait(stat_xy, imgName): # Get median median = genutil.statistics.median(stat_xy, axis=1)[0] print(median) print(median.shape) # Match shapes stat_xy, median = genutil.grower(stat_xy, median) print(stat_xy.shape) print(median.shape) # Normalize by median value median = np.array(median) stat_xy_normalized = MV2.divide(MV2.subtract(stat_xy, median), median) print(stat_xy_normalized.shape) stat_xy_normalized.setAxisList(stat_xy.getAxisList()) # # Plotting # # Set up VCS Canvas class VCSAddonsNotebook(object): def __init__(self, x): self.x = x def _repr_png_(self): fnm = tempfile.mktemp() + ".png" self.x.png(fnm) encoded = base64.b64encode(open(fnm, "rb").read()) return encoded def __call__(self): return self # VCS Canvas x = vcs.init(bg=True, geometry=(2600, 800)) show = VCSAddonsNotebook(x) # Load our "pretty" colormap x.scriptrun( os.path.join(sys.prefix, "share", "pmp", "graphics", 'vcs', 'portraits.scr')) # Set up Portrait Plot P = pcmdi_metrics.graphics.portraits.Portrait() xax = [t + ' ' for t in stat_xy_normalized.getAxis(1)[:]] yax = [t + ' ' for t in stat_xy_normalized.getAxis(0)[:]] # Preprocessing step to "decorate" the axis P.decorate(stat_xy_normalized, yax, xax) # # Customize # SET = P.PLOT_SETTINGS # Viewport on the Canvas SET.x1 = .05 SET.x2 = .88 SET.y1 = .25 SET.y2 = .9 # Both X (horizontal) and y (VERTICAL) ticks # Text table SET.tictable = vcs.createtexttable() SET.tictable.color = "black" # X (bottom) ticks tictextsize = 9 # Text Orientation SET.xticorientation = vcs.createtextorientation() SET.xticorientation.angle = -90 SET.xticorientation.halign = "right" SET.xticorientation.height = tictextsize # Y (vertical) ticks SET.yticorientation = vcs.createtextorientation() SET.yticorientation.angle = 0 SET.yticorientation.halign = "right" SET.yticorientation.height = tictextsize # We can turn off the "grid" SET.draw_mesh = "y" # Control color for missing SET.missing_color = "grey" # Tics length SET.xtic1.y1 = 0 SET.xtic1.y2 = 0 # Timestamp SET.time_stamp = None # Colormap SET.colormap = "bl_to_darkred" # level to use SET.levels = [-.5, -.4, -.3, -.2, -.1, 0, .1, .2, .3, .4, .5] SET.levels.insert(0, -1.e20) SET.levels.append(1.e20) # colors to use SET.fillareacolors = vcs.getcolors(SET.levels, split=0, colors=range(16, 240)) # Plot P.plot(stat_xy_normalized, x=x) # Save x.png(imgName + '.png') # # Annotated Plot # Annotated = False if Annotated: x.clear() SET.values.show = True SET.values.array = stat_xy P.plot(stat_xy_normalized, x=x, bg=0) x.png(imgName + '_annotated.png')
def build_templates(canvas=None, graphicMethodStrings=None, overlay=None, rows=1, columns=1, mainTemplateOptions=None, templateOptionsArray=None, templateNameArray=None, legendDirection='vertical', forceAspectRatio=False, onlyData=False, disableLegend=False): """ This function generates and adjusts the templates needed to plot the diagnostic plots. """ #debug: # debugInfoFunc(graphicMethodStrings, overlay, rows, columns, # mainTemplateOptions, templateOptionsArray, templateNameArray, # legendDirection, forceAspectRatio, onlyData) if rows == 0 or columns == 0: raise ValueError("One must enter a size bigger than zero for rows and columns.") exit(0) if ((graphicMethodStrings == None) or (mainTemplateOptions == None)) or ((overlay == None) or (canvas == None)): return (None, None) graphicMethodObjects = [] for i in range(len(graphicMethodStrings)): # make sure the graphics method exists if (graphicMethodStrings[i] == 'isofill') and ('uvwg' not in canvas.listelements('isofill')) : graphicMethodObjects.append( canvas.createisofill('uvwg_' + (str(random.random())[2:]), 'default') ) if (graphicMethodStrings[i] == 'isoline') and ('uvwg' not in canvas.listelements('isoline')) : graphicMethodObjects.append( canvas.createisoline('uvwg_' + (str(random.random())[2:]), 'default') ) if (graphicMethodStrings[i] == 'boxfill') and ('uvwg' not in canvas.listelements('boxfill')) : graphicMethodObjects.append( canvas.createisoline('uvwg_' + (str(random.random())[2:]), 'default') ) if (graphicMethodStrings[i] == 'yxvsx') and ('uvwg' not in canvas.listelements('yxvsx')) : graphicMethodObjects.append( canvas.createyxvsx('uvwg_' + (str(random.random())[2:]), 'default') ) if overlay[i] == 0: graphicMethodObjects[i].linewidth = 1.5 else: graphicMethodObjects[i].linewidth = 2.0 graphicMethodObjects[i].linetype = 'dash' graphicMethodObjects[i].linecolor = 242 if (graphicMethodStrings[i] == 'vector') and ('uvwg' not in canvas.listelements('vector')) : graphicMethodObjects.append( canvas.createvector('uvwg_' + (str(random.random())[2:]), 'default') ) ## kludge because new vectors seem to have HUGE arrows graphicMethodObjects[-1].scale=.03 if (graphicMethodStrings[i] == 'scatter') and ('uvwg' not in canvas.listelements('scatter')) : graphicMethodObjects.append( canvas.createscatter('uvwg_' + (str(random.random())[2:]), 'default') ) if overlay[i] == 0: graphicMethodObjects[i].markersize = 8 else: graphicMethodObjects[i].linewidth = 2.0 graphicMethodObjects[i].linecolor = 242 graphicMethodObjects[i].markersize = 1 if (graphicMethodStrings[i] == 'taylordiagram'): td = canvas.createtaylordiagram('taylor_' + (str(random.random())[2:]), 'default') graphicMethodObjects.append( td ) #graphicMethodObjects[i].addMarker() #graphicMethodObjects[i].Marker.size = 8 # if rows > columns: # canvas.portrait() # else: # canvas.landscape() # Creates EzTemplate M = EzTemplate.Multi(rows=rows, columns=columns) # Set EzTemplate Options M.legend.direction = legendDirection # default='horizontal' # Font size auto-scale scaleFactor = gaussian(float(max(rows, columns))/10.0, 0.1, 0.45) # Title size auto-scale if (rows == columns) and (rows ==1): titleScaleFactor = 1.3*scaleFactor else: titleScaleFactor = linear(float(max(rows, columns))) # Get from yxvsx_merra_tas.py # Set conversion factor to multiply font height coordinates by # to obtain the value in normalized coordinates. This is set # by trial-and-error: fontht2norm = 0.0007 dx = calcdx(M, rows, columns) dy = calcdy(M, rows, columns) # Aspect Ratio: if forceAspectRatio: if dx > 2*dy: while calcdx(M, rows, columns) > 2*dy: M.margins.left += 0.01 M.margins.right += 0.01 elif 2*dy > dx: while 2*calcdy(M, rows, columns) > dx: M.margins.top += 0.01 M.margins.bottom += 0.01 # Adjusts margins and vertical spaces to # handle title-data or title-(out of box) problems if mainTemplateOptions.title: y1_row0 = calcy1(M, 0, dy, 0.0) y1_row1 = calcy1(M, 1, dy, 0.0) y2_row1 = calcy2(y1_row1, dy, 0.0) title_height = 14 * fontht2norm # 14 is the default font size if rows > 1: Mt = EzTemplate.Multi(rows=rows, columns=columns, legend_direction=legendDirection) Mt.margins = M.margins Mt.spacing = M.spacing # Avoiding overlay of titles and xnames: templateAbove = Mt.get(row=0, column=0, legend='local', font=False) templateBelow = Mt.get(row=1, column=0, legend='local', font=False) titleBelowY2 = title_height + templateBelow.title.y xnameAboveY = templateAbove.xname.y del templateAbove del templateBelow titleAbove_Y = 0.0 while (titleBelowY2 > xnameAboveY): Mt.spacing.vertical += 0.01 templateBelow = Mt.get(row=1, column=0, legend='local', font=False) templateAbove = Mt.get(row=0, column=0, legend='local', font=False) titleBelowY2 = title_height + templateBelow.title.y xnameAboveY = templateAbove.xname.y titleAbove_Y = templateAbove.title.y del templateAbove del templateBelow # Avoiding titles out of bounds titleAboveY2 = title_height + titleAbove_Y while titleAboveY2 > 1.0: Mt.margins.top += 0.01 Mt.margins.bottom += 0.01 templateAbove = Mt.get(row=0, column=0, legend='local') titleAboveY2 = title_height + templateAbove.title.y del templateAbove M.spacing = Mt.spacing M.margins = Mt.margins del Mt elif rows == 1: title_height = 60 * fontht2norm # one plot per page has a different scale Mt = EzTemplate.Multi(rows=rows, columns=columns) Mt.margins = M.margins Mt.spacing = M.spacing tt = Mt.get(row=0, column=0, legend='local') tt.scalefont(scaleFactor) titley2 = title_height * scaleFactor + tt.title.y del tt # Avoiding titles out of bounds while titley2 > 1.0: Mt.margins.top += 0.01 Mt.margins.bottom += 0.01 tt = Mt.get(row=0, column=0, legend='local') titley2 = title_height * scaleFactor + tt.title.y del tt M.margins = Mt.margins M.spacing = Mt.spacing del Mt # Adjusts the Xname position related to out of page problems if mainTemplateOptions.xname: Mt = EzTemplate.Multi(rows=rows, columns=columns, legend_direction=legendDirection) Mt.margins = M.margins Mt.spacing = M.spacing tt = None if rows > 1 : tt = Mt.get(row=rows-1, column=0, legend='local') else: tt = Mt.get(row=0, column=0, legend='local') xnameY = tt.xname.y del tt # 0.004 was found by trying-error procedure while xnameY < 0.004: Mt.margins.top += 0.01 Mt.margins.bottom += 0.01 if rows > 1 : tt = Mt.get(row=rows-1, column=0, legend='local') else: tt = Mt.get(row=0, column=0, legend='local') xnameY = tt.xname.y del tt #print "xnameY = ", xnameY M.margins.top = Mt.margins.top M.margins.bottom = Mt.margins.bottom del Mt # Adjust the xname position related to other plots in the same page if mainTemplateOptions.xname: y1_row0 = calcy1(M, 0, dy, 0.0) y1_row1 = calcy1(M, 1, dy, 0.0) y2_row1 = calcy2(y1_row1, dy, 0.0) if rows > 1: Mt = EzTemplate.Multi(rows=rows, columns=columns, legend_direction=legendDirection) Mt.margins.top = M.margins.top Mt.margins.bottom = M.margins.bottom Mt.spacing.vertical = M.spacing.vertical Mt.spacing.horizontal = M.spacing.horizontal tt = Mt.get(row=0, column=0, legend='local') xnameY = tt.xname.y del tt # Avoiding overlay of xnames and data while xnameY < (y2_row1 + 0.01*y2_row1): Mt.spacing.vertical += 0.01 dy = calcdy(Mt, rows, columns) y1_row1 = calcy1(Mt, 1, dy, 0.0) y2_row1 = calcy2(y1_row1, dy, 0.0) #print "dy = {0}, y1_row1 = {1}, y2_row1 = {2}".format(dy, y1_row1, y2_row1) M.spacing.vertical = Mt.spacing.vertical del Mt # Adjusts the Ylabel1 position related to out of page problems if mainTemplateOptions.ylabel1: Mt = EzTemplate.Multi(rows=rows, columns=columns, legend_direction=legendDirection) Mt.margins = M.margins Mt.spacing = M.spacing tt = Mt.get(row=0, column=0, legend='local', font=False) ylabel1X = tt.ylabel1.x del tt while ylabel1X < 0.0: Mt.margins.left += 0.01 Mt.margins.right += 0.01 tt = Mt.get(row=0, column=0, legend='local') ylabel1X = tt.ylabel1.x del tt M.margins = Mt.margins M.spacing = Mt.spacing del Mt # Adjusts the Yname position related to out of page problems # if mainTemplateOptions.yname: # Mt = EzTemplate.Multi(rows=rows, columns=columns, legend_direction=legendDirection) # Mt.legend.direction = legendDirection # Mt.margins = M.margins # Mt.spacing = M.spacing # tt = Mt.get(row=0, column=0, legend='local') # ynamex = tt.yname.x # while ynamex < 0.0: # Mt.margins.left *= 1.01 # Mt.margins.right *= 1.01 # tt = Mt.get(row=0, column=0, legend='local') # ynamex = tt.yname.x # M.margins.left = Mt.margins.left # M.margins.right = Mt.margins.right # Adjusts yname position related to the page margins if mainTemplateOptions.yname: Mt = EzTemplate.Multi(rows=rows, columns=columns, legend_direction=legendDirection) Mt.spacing = M.spacing Mt.margins = M.margins tt = Mt.get(row=0, column=0, legend='local', font=False) while tt.yname.x < 0.0015: Mt.margins.left += 0.05 del tt tt = Mt.get(row=0, column=0, legend='local', font=False) del tt M.margins = Mt.margins M.spacing = Mt.spacing del Mt # Adjusts the Yname position related to other plots in the same page if mainTemplateOptions.yname and (columns > 1): Mt = EzTemplate.Multi(rows=rows, columns=columns, legend_direction=legendDirection) Mt.legend.direction = legendDirection Mt.margins = M.margins Mt.spacing = M.spacing tt = Mt.get(row=0, column=0, legend='local') # takes legend changes in effect... delta = float(tt.data.x2 - tt.data.x1) posx2 = tt.legend.x1 + 0.09*delta if posx2 > 1.0: posx2 = tt.legend.x1 + 0.05*delta legendx2 = posx2 del tt tt2 = Mt.get(row=0, column=1, legend='local') ynamex = tt2.yname.x del tt2 while ynamex < legendx2: Mt.spacing.horizontal += 0.01 tt = Mt.get(row=0, column=0, legend='local') # takes legend changes in effect... delta = float(tt.data.x2 - tt.data.x1) posx2 = tt.legend.x1 + 0.09*delta if posx2 > 1.0: posx2 = tt.legend.x1 + 0.05*delta legendx2 = posx2 tt2 = Mt.get(row=0, column=1, legend='local') ynamex = tt2.yname.x del tt del tt2 #M.spacing.horizontal = Mt.spacing.horizontal M.margins = Mt.margins M.spacing = Mt.spacing del Mt # Adjusts legend position if mainTemplateOptions.legend: Mt = EzTemplate.Multi(rows=rows, columns=columns, legend_direction=legendDirection) Mt.legend.direction = legendDirection Mt.margins = M.margins Mt.spacing = M.spacing tt = Mt.get(row=0, column=0, legend='local', font=False) # takes legend changes in effect... delta = float(tt.data.x2 - tt.data.x1) if legendDirection == 'vertical': posx2 = tt.legend.x1 + 0.09*delta if posx2 > 1.0: posx2 = tt.legend.x1 + 0.05*delta legendx2 = posx2 while legendx2 > 0.955: Mt.margins.left += 0.01 Mt.margins.right += 0.01 del tt tt = Mt.get(row=0, column=0, legend='local', font=False) # takes legend changes in effect... delta = float(tt.data.x2 - tt.data.x1) posx2 = tt.legend.x1 + 0.09*delta if posx2 > 1.0: posx2 = tt.legend.x1 + 0.06*delta legendx2 = posx2 elif legendDirection == 'horizontal': # Fix bug where ynames and values are out of bound in display but not in value. Mt.margins.left += 0.025 while tt.ylabel1.x < 0.0015: Mt.margins.left += 0.1 del tt tt = Mt.get(row=0, column=0, legend='local', font=False) M.margins.left = Mt.margins.left M.margins.right = Mt.margins.right del Mt # Adjusts vertical spacing if Mean is enabled and the aspect-ration is being forced: if mainTemplateOptions.mean and forceAspectRatio: Mt = EzTemplate.Multi(rows=rows, columns=columns, legend_direction=legendDirection) Mt.margins.top = M.margins.top Mt.margins.bottom = M.margins.bottom Mt.spacing.vertical = M.spacing.vertical Mt.spacing.horizontal = M.spacing.horizontal tt = Mt.get(row=0, column=0, legend='local') tt.scalefont(scaleFactor) tt.mean.x = tt.title.x mean_orientation = vcs.gettextorientation(tt.mean.textorientation) mean_orientation.halign = "center" mean_orientation.valign = "top" mean_orientation.height *= scaleFactor*0.7 tt.mean.textorientation = mean_orientation mean_orientation = None # 0.009 was found empirically if math.fabs(tt.mean.y - tt.data.y2) < 0.009: while math.fabs(tt.mean.y - tt.data.y2) < 0.009: Mt.margins.top += 0.01 Mt.margins.bottom += 0.01 del tt tt = Mt.get(row=0, column=0, legend='local') tt.scalefont(scaleFactor) M.margins.top = Mt.margins.top M.margins.bottom = Mt.margins.bottom del Mt else: del tt ###################### # Generating Templates finalTemplates = [] for i in range(len(graphicMethodStrings)): if (len(overlay) > 1) and (overlay[i] == 1): lastTemplate = finalTemplates[-1] cpLastTemplate = canvas.createtemplate(lastTemplate.name+'_overlay', lastTemplate.name) # Avoiding legend overlaping. cpLastTemplate.legend.y1 += 0.01 setTemplateOptions(cpLastTemplate, templateOptionsArray[i]) finalTemplates.append(cpLastTemplate) continue # Template name #if (templateNameArray is not None) and (len(templateNameArray) > i): # M.template = templateNameArray[i] if (templateNameArray is not None) and (len(templateNameArray) > i): template = M.get(legend='local',tname=templateNameArray[i]) else: template = M.get(legend='local') # scale fonts template.scalefont(scaleFactor) if mainTemplateOptions.title: # Align title delta = template.data.x2 - template.data.x1 template.title.x = template.data.x1 + float(delta)/2.0 if rows == 1: template.title.y *= 0.99 title_orientation = vcs.createtextorientation() title_orientation.halign = "center" title_orientation.height *= titleScaleFactor # 100 * deltaY # default = 14 template.title.textorientation = title_orientation title_orientation = None if mainTemplateOptions.dataname: template.dataname.x = template.data.x1 template.dataname.y = template.data.y2 + 0.01 dataname_orientation = vcs.gettextorientation(template.dataname.textorientation) dataname_orientation.height *= 0.98 template.dataname.textorientation = dataname_orientation dataname_orientation = None if mainTemplateOptions.legend: if legendDirection == 'vertical': template.legend.offset += 0.0095 # Adjusting legend position delta = template.data.x2 - template.data.x1 posx2 = template.legend.x1 + 0.08*delta if posx2 > 1.0: posx2 = template.legend.x1 + 0.05*delta template.legend.x2 = posx2 elif legendDirection == 'horizontal': # Adjusting legend position template.legend.x1 = template.data.x1 template.legend.x2 = template.data.x2 deltaL = template.legend.y2 - template.legend.y1 template.legend.y2 = template.xname.y - 0.03 template.legend.y1 = template.legend.y2 - deltaL - 0.01 if mainTemplateOptions.mean: # Align Mean template.mean.x = template.title.x if rows == 1: template.mean.y *= 0.99 mean_orientation = vcs.createtextorientation() mean_orientation.halign = "center" #mean_orientation.valign = "top" if (rows == columns) and (rows ==1): mean_orientation.height *= scaleFactor*0.88 else: mean_orientation.height *= scaleFactor*0.65 template.mean.textorientation = mean_orientation mean_orientation = None if mainTemplateOptions.xname: #template.xname.y *= 1.01 xname_orientation = vcs.gettextorientation(template.xname.textorientation) xname_orientation.halign = "center" #xname_orientation.valign = "bottom" xname_orientation.height *= 0.85 template.xname.textorientation = xname_orientation xname_orientation = None if mainTemplateOptions.yname: #template.yname.y *= 1.01 yname_orientation = vcs.gettextorientation(template.yname.textorientation) yname_orientation.halign = "center" #yname_orientation.valign = "top" yname_orientation.height *= 0.85 template.yname.textorientation = yname_orientation yname_orientation = None if mainTemplateOptions.xlabel1: #template.xlabel1.y *= 1.01 xlabel1_orientation = vcs.gettextorientation(template.xlabel1.textorientation) #xlabel1_orientation.halign = "center" #xlabel1_orientation.valign = "bottom" xlabel1_orientation.height *= 0.85 template.xlabel1.textorientation = xlabel1_orientation xlabel1_orientation = None if mainTemplateOptions.ylabel1: #template.ylabel1.y *= 1.01 ylabel1_orientation = vcs.gettextorientation(template.ylabel1.textorientation) #ylabel1_orientation.halign = "center" #ylabel1_orientation.valign = "bottom" ylabel1_orientation.height *= 0.85 template.ylabel1.textorientation = ylabel1_orientation ylabel1_orientation = None if mainTemplateOptions.units: template.units.x = template.data.x2 - (5*14*fontht2norm) # 5 charactes if mainTemplateOptions.mean: template.units.y = template.mean.y else: template.units.y = template.data.y2 + 0.01 units_orientation = vcs.gettextorientation(template.units.textorientation) units_orientation.halign = "left" #units_orientation.valign = "bottom" units_orientation.height *= 0.85 template.units.textorientation = units_orientation units_orientation = None if mainTemplateOptions.min: template.min.x = template.legend.x1 if mainTemplateOptions.max: minTo = canvas.gettextorientation(template.min.textorientation) minheight = minTo.height * fontht2norm minTo = None template.max.x = template.legend.x1 if (rows == columns) and (rows ==1): template.max.y = template.min.y - 1.55*minheight else: template.max.y = template.min.y - 1.35*minheight if onlyData: dudTemplate = TemplateOptions() dudTemplate.setAllFalse() dudTemplate.data = True setTemplateOptions(template, dudTemplate) else: if (templateOptionsArray is not None) and (len(templateOptionsArray) > i): setTemplateOptions(template, templateOptionsArray[i]) else: setTemplateOptions(template, mainTemplateOptions) if disableLegend == True: template.legend.priority = 0 finalTemplates.append(template) return (graphicMethodObjects, finalTemplates)
def generateTemplate(self): template = vcs.createtemplate() # Now sets all the things for the template... # Sets a bunch of template attributes to off for att in [ "line1", "line2", "line3", "line4", "box2", "box3", "box4", "min", "max", "mean", "xtic1", "xtic2", "ytic1", "ytic2", "xvalue", "yvalue", "zvalue", "tvalue", "xunits", "yunits", "zunits", "tunits", "source", "title", "dataname", ]: a = getattr(template, att) setattr(a, "priority", 0) for att in [ "xname", "yname", ]: a = getattr(template, att) setattr(a, "priority", 0) template.data.x1 = self.PLOT_SETTINGS.x1 template.data.x2 = self.PLOT_SETTINGS.x2 template.data.y1 = self.PLOT_SETTINGS.y1 template.data.y2 = self.PLOT_SETTINGS.y2 template.box1.x1 = self.PLOT_SETTINGS.x1 template.box1.x2 = self.PLOT_SETTINGS.x2 template.box1.y1 = self.PLOT_SETTINGS.y1 template.box1.y2 = self.PLOT_SETTINGS.y2 template.xname.y = self.PLOT_SETTINGS.y2 + 0.02 template.yname.x = self.PLOT_SETTINGS.x2 + 0.01 template.xlabel1.y = self.PLOT_SETTINGS.y1 template.xlabel2.y = self.PLOT_SETTINGS.y2 template.xlabel1.texttable = self.PLOT_SETTINGS.tictable template.xlabel2.texttable = self.PLOT_SETTINGS.tictable template.xlabel1.textorientation = self.PLOT_SETTINGS.xticorientation template.xlabel2.textorientation = self.PLOT_SETTINGS.xticorientation template.ylabel1.x = self.PLOT_SETTINGS.x1 template.ylabel2.x = self.PLOT_SETTINGS.x2 template.ylabel1.texttable = self.PLOT_SETTINGS.tictable template.ylabel2.texttable = self.PLOT_SETTINGS.tictable template.ylabel1.textorientation = self.PLOT_SETTINGS.yticorientation template.ylabel2.textorientation = self.PLOT_SETTINGS.yticorientation if self.PLOT_SETTINGS.xtic1.y1 is not None: template.xtic1.y1 = self.PLOT_SETTINGS.xtic1.y1 template.xtic1.priority = 1 if self.PLOT_SETTINGS.xtic1.y2 is not None: template.xtic1.y2 = self.PLOT_SETTINGS.xtic1.y2 template.xtic1.priority = 1 if self.PLOT_SETTINGS.xtic2.y1 is not None: template.xmintic2.y1 = self.PLOT_SETTINGS.xtic2.y1 template.xmintic2.priority = 1 if self.PLOT_SETTINGS.xtic2.y2 is not None: template.xmintic2.y2 = self.PLOT_SETTINGS.xtic2.y2 template.xmintic2.priority = 1 if self.PLOT_SETTINGS.ytic1.x1 is not None: template.ytic1.x1 = self.PLOT_SETTINGS.ytic1.x1 template.ytic1.priority = 1 if self.PLOT_SETTINGS.ytic1.x2 is not None: template.ytic1.x2 = self.PLOT_SETTINGS.ytic1.x2 template.ytic1.priority = 1 if self.PLOT_SETTINGS.ytic2.x1 is not None: template.ymintic2.priority = 1 template.ymintic2.x1 = self.PLOT_SETTINGS.ytic2.x1 if self.PLOT_SETTINGS.ytic2.x2 is not None: template.ymintic2.priority = 1 template.ymintic2.x2 = self.PLOT_SETTINGS.ytic2.x2 template.legend.x1 = self.PLOT_SETTINGS.legend.x1 template.legend.x2 = self.PLOT_SETTINGS.legend.x2 template.legend.y1 = self.PLOT_SETTINGS.legend.y1 template.legend.y2 = self.PLOT_SETTINGS.legend.y2 try: tmp = vcs.createtextorientation("crap22") except Exception: tmp = vcs.gettextorientation("crap22") tmp.height = 12 # tmp.halign = 'center' # template.legend.texttable = tmp template.legend.textorientation = tmp return template