def setMarkerObject(self, markerobject): self.markerobj = markerobject tmpobj = vcs.createmarker(source=self.markerobj) tmpobj.x = [.5, .5] tmpobj.y = [.5, .5] self.clear() self.plot(tmpobj)
def test_preview(): prev = MarkerPreview.MarkerPreviewWidget() marker = vcs.createmarker("test") prev.setMarkerObject(marker) assert prev.markerobj == marker marker.type = "cross" prev.update() assert prev.markerobj.type == ["cross"]
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()
src=sys.argv[1] if os.path.exists("test_vcs_dump_json.json"): os.remove("test_vcs_dump_json.json") b = vcs.createboxfill("Charles.Doutriaux") b.script("test_vcs_dump_json","a") b = vcs.createisofill("Charles.Doutriaux") b.script("test_vcs_dump_json","a") b = vcs.createisoline("Charles.Doutriaux") b.script("test_vcs_dump_json","a") b = vcs.createmeshfill("Charles.Doutriaux") b.script("test_vcs_dump_json","a") b = vcs.createoneD("Charles.Doutriaux") b.script("test_vcs_dump_json","a") b = vcs.createfillarea("Charles.Doutriaux") b.script("test_vcs_dump_json","a") b = vcs.createtext("Charles.Doutriaux") b.script("test_vcs_dump_json","a") b = vcs.createline("Charles.Doutriaux") b.script("test_vcs_dump_json","a") b = vcs.createmarker("Charles.Doutriaux") b.script("test_vcs_dump_json","a") b = vcs.createtemplate("Charles.Doutriaux") b.script("test_vcs_dump_json","a") b = vcs.createprojection("Charles.Doutriaux") b.script("test_vcs_dump_json","a") assert(filecmp.cmp("test_vcs_dump_json.json",src))
def plot(self, var, theta=None, template=None, bg=0, x=None): """ Plots a polar plot of your data. If var is an ndarray with the second dimension being 2, it will use the first value as magnitude and the second as theta. Otherwise, if theta is provided, it uses var as magnitude and the theta given. """ if x is None: if self.x is None: self.x = vcs.init() x = self.x if template is None: template = self.template if self.markercolorsource.lower() not in ("group", "magnitude", "theta"): raise ValueError( "polar.markercolorsource must be one of: 'group', 'magnitude', 'theta'" ) magnitudes, thetas, names = convert_arrays(var, theta) if not self.negative_magnitude: # negative amplitude means 180 degree shift neg = numpy.ma.less(magnitudes, 0.0) magnitudes = numpy.ma.abs(magnitudes) thetas = numpy.ma.where(neg, theta + numpy.pi, theta) if self.group_names: names = self.group_names while len(names) < len(magnitudes): names.append(None) flat_magnitude = numpy.ravel(magnitudes) canvas = x # Determine aspect ratio for plotting the circle canvas_info = canvas.canvasinfo() # Calculate aspect ratio of window window_aspect = canvas_info["width"] / float(canvas_info["height"]) if window_aspect > 1: ymul = window_aspect xmul = 1 else: ymul = 1 xmul = window_aspect # Use window_aspect to adjust size of template.data x0, x1 = template.data.x1, template.data.x2 y0, y1 = template.data.y1, template.data.y2 xdiff = abs(x1 - x0) ydiff = abs(y1 - y0) center = x0 + xdiff / 2., y0 + ydiff / 2. diameter = min(xdiff, ydiff) radius = diameter / 2. plot_kwargs = {"render": False, "bg": bg, "donotstoredisplay": True} # Outer line if template.box1.priority > 0: outer = vcs.createline(source=template.box1.line) x, y = circle_points(center, radius, ratio=window_aspect) outer.x = x outer.y = y canvas.plot(outer, **plot_kwargs) del vcs.elements["line"][outer.name] if numpy.allclose((self.datawc_y1, self.datawc_y2), 1e20): if self.magnitude_ticks == "*": m_scale = vcs.mkscale(*vcs.minmax(flat_magnitude)) else: if isinstance(self.magnitude_ticks, str): ticks = vcs.elements["list"][self.magnitude_ticks] else: ticks = self.magnitude_ticks m_scale = ticks else: m_scale = vcs.mkscale(self.datawc_y1, self.datawc_y2) if template.ytic1.priority > 0: m_ticks = vcs.createline(source=template.ytic1.line) m_ticks.x = [] m_ticks.y = [] if template.ylabel1.priority > 0: to = self.text_orientation_for_angle( self.magnitude_tick_angle + self.theta_offset, source=template.ylabel1.textorientation) m_labels = self.create_text(template.ylabel1.texttable, to) m_labels.x = [] m_labels.y = [] m_labels.string = [] if self.yticlabels1 == "*": mag_labels = vcs.mklabels(m_scale) else: mag_labels = self.yticlabels1 else: m_labels = None for lev in m_scale: lev_radius = radius * self.magnitude_from_value(lev, m_scale) x, y = circle_points(center, lev_radius, ratio=window_aspect) if m_labels is not None: if lev in mag_labels: m_labels.string.append(mag_labels[lev]) m_labels.x.append(xmul * lev_radius * numpy.cos(self.magnitude_tick_angle + self.theta_offset) + center[0]) m_labels.y.append(ymul * lev_radius * numpy.sin(self.magnitude_tick_angle + self.theta_offset) + center[1]) m_ticks.x.append(x) m_ticks.y.append(y) canvas.plot(m_ticks, **plot_kwargs) del vcs.elements["line"][m_ticks.name] if m_labels is not None: canvas.plot(m_labels, **plot_kwargs) del vcs.elements["textcombined"][m_labels.name] if template.ymintic1.priority > 0 and self.magnitude_mintics is not None: mag_mintics = vcs.createline(source=template.ymintic1.line) mag_mintics.x = [] mag_mintics.y = [] mintics = self.magnitude_mintics if isinstance(mintics, str): mintics = vcs.elements["list"][mintics] for mag in mintics: mintic_radius = radius * \ self.magnitude_from_value(mag, m_scale) x, y = circle_points(center, mintic_radius, ratio=window_aspect) mag_mintics.x.append(x) mag_mintics.y.append(y) canvas.plot(mag_mintics, **plot_kwargs) del vcs.elements["line"][mag_mintics.name] if self.xticlabels1 == "*": if numpy.allclose((self.datawc_x1, self.datawc_x2), 1e20): tick_thetas = list(numpy.arange(0, numpy.pi * 2, numpy.pi / 4)) tick_labels = {t: str(t) for t in tick_thetas} else: d_theta = (self.datawc_x2 - self.datawc_x1) / \ float(self.theta_tick_count) tick_thetas = numpy.arange(self.datawc_x1, self.datawc_x2 + .0001, d_theta) tick_labels = vcs.mklabels(tick_thetas) else: tick_thetas = sorted(list(self.xticlabels1.keys())) tick_labels = self.xticlabels1 if template.xtic1.priority > 0: t_ticks = vcs.createline(source=template.xtic1.line) t_ticks.x = [] t_ticks.y = [] if template.xlabel1.priority > 0: t_labels = [] theta_labels = tick_labels else: t_labels = None for t in tick_thetas: angle = self.theta_from_value(t) x0 = center[0] + (xmul * radius * numpy.cos(angle)) x1 = center[0] y0 = center[1] + (ymul * radius * numpy.sin(angle)) y1 = center[1] if t_labels is not None: label = self.create_text( template.xlabel1.texttable, self.text_orientation_for_angle( angle, source=template.xlabel1.textorientation)) label.string = [theta_labels[t]] label.x = [x0] label.y = [y0] t_labels.append(label) t_ticks.x.append([x0, x1]) t_ticks.y.append([y0, y1]) canvas.plot(t_ticks, **plot_kwargs) del vcs.elements["line"][t_ticks.name] if t_labels is not None: for l in t_labels: canvas.plot(l, **plot_kwargs) del vcs.elements["textcombined"][l.name] values = vcs.createmarker() values.type = self.markertypes values.size = self.markersizes values.color = self.markercolors values.colormap = self.colormap values.priority = self.markerpriority values.x = [] values.y = [] if template.legend.priority > 0: # Only labels that are set will show up in the legend label_count = len(names) - len([i for i in names if i is None]) labels = self.create_text(template.legend.texttable, template.legend.textorientation) labels.x = [] labels.y = [] labels.string = [] if self.linepriority > 0: line = vcs.createline() line.x = [] line.y = [] line.type = self.linetypes line.color = self.linecolors if self.linecolors is not None else self.markercolors line.width = self.linewidths line.priority = self.linepriority # This is up here because when it's part of the main loop, we can # lose "order" of points when we flatten them. for mag, theta in zip(magnitudes, thetas): x = [] y = [] for m, t in zip(mag, theta): t = self.theta_from_value(t) r = self.magnitude_from_value(m, m_scale) * radius if r == numpy.nan: continue x.append(xmul * numpy.cos(t) * r + center[0]) y.append(ymul * numpy.sin(t) * r + center[1]) if self.connect_groups: line.x.extend(x) line.y.extend(y) else: line.x.append(x) line.y.append(y) if self.markercolorsource.lower() in ('magnitude', "theta"): # Regroup the values using the appropriate metric mag_flat = numpy.array(magnitudes).flatten() theta_flat = numpy.array(thetas).flatten() if self.markercolorsource.lower() == "magnitude": scale = m_scale vals = mag_flat else: scale = tick_thetas vals = theta_flat indices = [ numpy.where( numpy.logical_and(vals >= scale[i], vals <= scale[i + 1])) for i in range(len(scale) - 1) ] magnitudes = [mag_flat[inds] for inds in indices] thetas = [theta_flat[inds] for inds in indices] names = vcs.mklabels(scale, output="list") names = [ names[i] + " - " + names[i + 1] for i in range(len(names) - 1) ] label_count = len(names) for mag, theta, name in zip(magnitudes, thetas, names): x = [] y = [] for m, t in zip(mag, theta): t = self.theta_from_value(t) r = self.magnitude_from_value(m, m_scale) * radius x.append(xmul * numpy.cos(t) * r + center[0]) y.append(ymul * numpy.sin(t) * r + center[1]) if template.legend.priority > 0 and name is not None: y_offset = len(labels.x) / float(label_count) * \ (template.legend.y2 - template.legend.y1) lx, ly = template.legend.x1, template.legend.y1 + y_offset x.append(lx) y.append(ly) labels.x.append(lx + .01) labels.y.append(ly) labels.string.append(str(name)) values.x.append(x) values.y.append(y) if template.legend.priority > 0: canvas.plot(labels, **plot_kwargs) del vcs.elements["textcombined"][labels.name] if self.linepriority > 0: canvas.plot(line, **plot_kwargs) del vcs.elements["line"][line.name] for el in self.to_cleanup: if vcs.istexttable(el): if el.name in vcs.elements["texttable"]: del vcs.elements["texttable"][el.name] else: if el.name in vcs.elements["textorientation"]: del vcs.elements["textorientation"][el.name] self.to_cleanup = [] # Prune unneeded levels from values to_prune = [] for ind, (x, y) in enumerate(zip(values.x, values.y)): if x and y: continue else: to_prune.append(ind) for prune_ind in to_prune[::-1]: del values.x[prune_ind] del values.y[prune_ind] if len(values.color) > prune_ind and len(values.color) > 1: del values.color[prune_ind] if len(values.size) > prune_ind and len(values.size) > 1: del values.size[prune_ind] if len(values.type) > prune_ind and len(values.type) > 1: del values.type[prune_ind] canvas.plot(values, bg=bg, donotstoredisplay=True) del vcs.elements["marker"][values.name] return canvas
def editor(): editor = MarkerEditor.MarkerEditorWidget() marker = vcs.createmarker() editor.setMarkerObject(marker) return editor
os.remove("test_vcs_dump_json.json") b = vcs.createboxfill("vcs_instance") b.script("test_vcs_dump_json", "a") b = vcs.createisofill("vcs_instance") b.script("test_vcs_dump_json", "a") b = vcs.createisoline("vcs_instance") b.script("test_vcs_dump_json", "a") b = vcs.createmeshfill("vcs_instance") b.script("test_vcs_dump_json", "a") b = vcs.create1d("vcs_instance") b.script("test_vcs_dump_json", "a") b = vcs.createfillarea("vcs_instance") b.script("test_vcs_dump_json", "a") b = vcs.createvector("vcs_instance") b.script("test_vcs_dump_json", "a") b = vcs.createtext("vcs_instance") b.script("test_vcs_dump_json", "a") b = vcs.createline("vcs_instance") b.script("test_vcs_dump_json", "a") b = vcs.createmarker("vcs_instance") b.script("test_vcs_dump_json", "a") b = vcs.createtemplate("vcs_instance") b.script("test_vcs_dump_json", "a") b = vcs.createprojection("vcs_instance") b.script("test_vcs_dump_json", "a") print "Comparing:", os.path.realpath("test_vcs_dump_json.json"), src assert (filecmp.cmp("test_vcs_dump_json.json", src)) os.remove("test_vcs_dump_json.json")
# Component time is a more useful format, that has the date/time in human-readable attributes print "Time:", relative_time.tocomponent() print "Lat:", lataxis[lat_index] print "Lon:", lonaxis[lon_index] # Now we can plot clt at the specified time, and stick a marker at the lat/lon x = vcs.init() template = x.createtemplate() template.scale(.66, "x") template.blank() template.data.priority = 1 x.plot(clt(time=time_index), template) marker = vcs.createmarker() marker.type = "cross" # data describes where the actual plot is placed on the canvas data = template.data # Viewport represents the area in which markers are drawn marker.viewport = (data.x1, data.x2, data.y1, data.y2) # Worldcoordinate represents the scale that x/y are given in marker.worldcoordinate = (min(lonaxis), max(lonaxis), min(lataxis), max(lataxis)) marker.x = [lonaxis[lon_index]] marker.y = [lataxis[lat_index]] marker.size = 10 x.plot(marker) murica = clt(time=time_index, latitude=(12, 80), longitude=(-150, -40))
import vcs, os, filecmp import vcs, numpy, os, sys src = sys.argv[1] if os.path.exists("test_vcs_dump_json.json"): os.remove("test_vcs_dump_json.json") b = vcs.createboxfill("Charles.Doutriaux") b.script("test_vcs_dump_json", "a") b = vcs.createisofill("Charles.Doutriaux") b.script("test_vcs_dump_json", "a") b = vcs.createisoline("Charles.Doutriaux") b.script("test_vcs_dump_json", "a") b = vcs.createmeshfill("Charles.Doutriaux") b.script("test_vcs_dump_json", "a") b = vcs.createoneD("Charles.Doutriaux") b.script("test_vcs_dump_json", "a") b = vcs.createfillarea("Charles.Doutriaux") b.script("test_vcs_dump_json", "a") b = vcs.createtext("Charles.Doutriaux") b.script("test_vcs_dump_json", "a") b = vcs.createline("Charles.Doutriaux") b.script("test_vcs_dump_json", "a") b = vcs.createmarker("Charles.Doutriaux") b.script("test_vcs_dump_json", "a") b = vcs.createtemplate("Charles.Doutriaux") b.script("test_vcs_dump_json", "a") b = vcs.createprojection("Charles.Doutriaux") b.script("test_vcs_dump_json", "a") assert (filecmp.cmp("test_vcs_dump_json.json", src))
cdutil.setTimeBoundsMonthly(tas) var = cdutil.averager(tas(squeeze=1), axis="xy") var = cdutil.ANNUALCYCLE.climatology(var) var.id = saved_id variables.append(var) # Customize the lines used to draw the plots line = vcs.createline() line.width = 2 line.color = [ "red", "blue", "salmon", "medium aquamarine", "orange", "chartreuse" ] line.type = ["dot", "dash", "dash-dot", "long-dash", "solid", "dash"] # Customize the markers drawn marker = vcs.createmarker() marker.size = 6 # You can just use the same colors as the lines marker.color = line.color marker.type = [ "triangle_up", "plus", "diamond", "circle", "cross", "triangle_down" ] # Middle of the month (from the time axis) months = { 15.5: "Jan", 45.0: "Feb", 74.5: "March", 105.0: "April", 135.5: "May", 166.0: "June",
os.remove("test_vcs_dump_json.json") b = vcs.createboxfill("vcs_instance") b.script("test_vcs_dump_json","a") b = vcs.createisofill("vcs_instance") b.script("test_vcs_dump_json","a") b = vcs.createisoline("vcs_instance") b.script("test_vcs_dump_json","a") b = vcs.createmeshfill("vcs_instance") b.script("test_vcs_dump_json","a") b = vcs.create1d("vcs_instance") b.script("test_vcs_dump_json","a") b = vcs.createfillarea("vcs_instance") b.script("test_vcs_dump_json","a") b = vcs.createvector("vcs_instance") b.script("test_vcs_dump_json","a") b = vcs.createtext("vcs_instance") b.script("test_vcs_dump_json","a") b = vcs.createline("vcs_instance") b.script("test_vcs_dump_json","a") b = vcs.createmarker("vcs_instance") b.script("test_vcs_dump_json","a") b = vcs.createtemplate("vcs_instance") b.script("test_vcs_dump_json","a") b = vcs.createprojection("vcs_instance") b.script("test_vcs_dump_json","a") assert(filecmp.cmp("test_vcs_dump_json.json", src))
# Component time is a more useful format, that has the date/time in human-readable attributes print "Time:", relative_time.tocomponent() print "Lat:", lataxis[lat_index] print "Lon:", lonaxis[lon_index] # Now we can plot clt at the specified time, and stick a marker at the lat/lon x = vcs.init() template = x.createtemplate() template.scale(0.66, "x") template.blank() template.data.priority = 1 x.plot(clt(time=time_index), template) marker = vcs.createmarker() marker.type = "cross" # data describes where the actual plot is placed on the canvas data = template.data # Viewport represents the area in which markers are drawn marker.viewport = (data.x1, data.x2, data.y1, data.y2) # Worldcoordinate represents the scale that x/y are given in marker.worldcoordinate = (min(lonaxis), max(lonaxis), min(lataxis), max(lataxis)) marker.x = [lonaxis[lon_index]] marker.y = [lataxis[lat_index]] marker.size = 10 x.plot(marker) murica = clt(time=time_index, latitude=(12, 80), longitude=(-150, -40))
def editor(): editor = MarkerEditorWidget() marker = vcs.createmarker() editor.setMarkerObject(marker) return editor
def plot(self, var, theta=None, template=None, bg=0, x=None): """ Plots a polar plot of your data. If var is an ndarray with the second dimension being 2, it will use the first value as magnitude and the second as theta. Otherwise, if theta is provided, it uses var as magnitude and the theta given. """ if x is None: if self.x is None: self.x = vcs.init() x = self.x if template is None: template = self.template if self.markercolorsource.lower() not in ("group", "magnitude", "theta"): raise ValueError("polar.markercolorsource must be one of: 'group', 'magnitude', 'theta'") magnitudes, thetas, names = convert_arrays(var, theta) if self.group_names: names = self.group_names while len(names) < len(magnitudes): names.append(None) flat_magnitude = [] for i in magnitudes: flat_magnitude.extend(i) flat_theta = [] for i in thetas: flat_theta.extend(i) canvas = x # Determine aspect ratio for plotting the circle canvas_info = canvas.canvasinfo() # Calculate aspect ratio of window window_aspect = canvas_info["width"] / float(canvas_info["height"]) if window_aspect > 1: ymul = window_aspect xmul = 1 else: ymul = 1 xmul = window_aspect # Use window_aspect to adjust size of template.data x0, x1 = template.data.x1, template.data.x2 y0, y1 = template.data.y1, template.data.y2 xdiff = abs(x1 - x0) ydiff = abs(y1 - y0) center = x0 + xdiff / 2., y0 + ydiff / 2. diameter = min(xdiff, ydiff) radius = diameter / 2. plot_kwargs = {"render": False, "bg": bg, "donotstoredisplay": True} # Outer line if template.box1.priority > 0: outer = vcs.createline(source=template.box1.line) x, y = circle_points(center, radius, ratio=window_aspect) outer.x = x outer.y = y canvas.plot(outer, **plot_kwargs) del vcs.elements["line"][outer.name] if numpy.allclose((self.datawc_y1, self.datawc_y2), 1e20): if self.magnitude_ticks == "*": m_scale = vcs.mkscale(*vcs.minmax(flat_magnitude)) else: if isinstance(self.magnitude_ticks, (str, unicode)): ticks = vcs.elements["list"][self.magnitude_ticks] else: ticks = self.magnitude_ticks m_scale = ticks else: m_scale = vcs.mkscale(self.datawc_y1, self.datawc_y2) if template.ytic1.priority > 0: m_ticks = vcs.createline(source=template.ytic1.line) m_ticks.x = [] m_ticks.y = [] if template.ylabel1.priority > 0: to = self.text_orientation_for_angle(self.magnitude_tick_angle, source=template.ylabel1.textorientation) m_labels = self.create_text(template.ylabel1.texttable, to) m_labels.x = [] m_labels.y = [] m_labels.string = [] if self.yticlabels1 == "*": mag_labels = vcs.mklabels(m_scale) else: mag_labels = self.yticlabels1 else: m_labels = None for lev in m_scale: lev_radius = radius * self.magnitude_from_value(lev, (m_scale[0], m_scale[-1])) x, y = circle_points(center, lev_radius, ratio=window_aspect) if m_labels is not None: if lev in mag_labels: m_labels.string.append(mag_labels[lev]) m_labels.x.append(xmul * lev_radius * numpy.cos(self.magnitude_tick_angle) + center[0]) m_labels.y.append(ymul * lev_radius * numpy.sin(self.magnitude_tick_angle) + center[1]) m_ticks.x.append(x) m_ticks.y.append(y) canvas.plot(m_ticks, **plot_kwargs) del vcs.elements["line"][m_ticks.name] if m_labels is not None: canvas.plot(m_labels, **plot_kwargs) del vcs.elements["textcombined"][m_labels.name] if template.ymintic1.priority > 0 and self.magnitude_mintics is not None: mag_mintics = vcs.createline(source=template.ymintic1.line) mag_mintics.x = [] mag_mintics.y = [] mintics = self.magnitude_mintics if isinstance(mintics, (str, unicode)): mintics = vcs.elements["list"][mintics] for mag in mintics: mintic_radius = radius * self.magnitude_from_value(mag, (m_scale[0], m_scale[-1])) x, y = circle_points(center, mintic_radius, ratio=window_aspect) mag_mintics.x.append(x) mag_mintics.y.append(y) canvas.plot(mag_mintics, **plot_kwargs) del vcs.elements["line"][mag_mintics.name] if self.xticlabels1 == "*": if numpy.allclose((self.datawc_x1, self.datawc_x2), 1e20): tick_thetas = list(numpy.arange(0, numpy.pi * 2, numpy.pi / 4)) tick_labels = {t: str(t) for t in tick_thetas} else: d_theta = (self.datawc_x2 - self.datawc_x1) / float(self.theta_tick_count) tick_thetas = numpy.arange(self.datawc_x1, self.datawc_x2 + .0001, d_theta) tick_labels = vcs.mklabels(tick_thetas) else: tick_thetas = self.xticlabels1.keys() tick_labels = self.xticlabels1 if template.xtic1.priority > 0: t_ticks = vcs.createline(source=template.xtic1.line) t_ticks.x = [] t_ticks.y = [] if template.xlabel1.priority > 0: t_labels = [] theta_labels = tick_labels else: t_labels = None for t in tick_thetas: angle = self.theta_from_value(t) x0 = center[0] + (xmul * radius * numpy.cos(angle)) x1 = center[0] y0 = center[1] + (ymul * radius * numpy.sin(angle)) y1 = center[1] if t_labels is not None: label = self.create_text(template.xlabel1.texttable, self.text_orientation_for_angle(angle, source=template.xlabel1.textorientation)) label.string = [theta_labels[t]] label.x = [x0] label.y = [y0] t_labels.append(label) t_ticks.x.append([x0, x1]) t_ticks.y.append([y0, y1]) canvas.plot(t_ticks, **plot_kwargs) del vcs.elements["line"][t_ticks.name] if t_labels is not None: for l in t_labels: canvas.plot(l, **plot_kwargs) del vcs.elements["textcombined"][l.name] values = vcs.createmarker() values.type = self.markers values.size = self.markersizes values.color = self.markercolors values.colormap = self.colormap values.priority = self.markerpriority values.x = [] values.y = [] if template.legend.priority > 0: # Only labels that are set will show up in the legend label_count = len(names) - len([i for i in names if i is None]) labels = self.create_text(template.legend.texttable, template.legend.textorientation) labels.x = [] labels.y = [] labels.string = [] if self.draw_lines: line = vcs.createline() line.x = [] line.y = [] line.type = self.lines line.color = self.linecolors if self.linecolors is not None else self.markercolors line.width = self.linewidths line.priority = self.linepriority # This is up here because when it's part of the main loop, we can lose "order" of points when we flatten them. for mag, theta in zip(magnitudes, thetas): x = [] y = [] for m, t in zip(mag, theta): t = self.theta_from_value(t) r = self.magnitude_from_value(m, (m_scale[0], m_scale[-1])) * radius x.append(xmul * numpy.cos(t) * r + center[0]) y.append(ymul * numpy.sin(t) * r + center[1]) if self.connect_groups: line.x.extend(x) line.y.extend(y) else: line.x.append(x) line.y.append(y) if self.markercolorsource.lower() in ('magnitude', "theta"): # Regroup the values using the appropriate metric mag_flat = numpy.array(magnitudes).flatten() theta_flat = numpy.array(thetas).flatten() if self.markercolorsource.lower() == "magnitude": scale = m_scale vals = mag_flat else: scale = theta_ticks vals = theta_flat indices = [numpy.where(numpy.logical_and(vals >= scale[i], vals <= scale[i + 1])) for i in range(len(scale) - 1)] magnitudes = [mag_flat[inds] for inds in indices] thetas = [theta_flat[inds] for inds in indices] names = vcs.mklabels(scale, output="list") names = [names[i] + " - " + names[i + 1] for i in range(len(names) - 1)] label_count = len(names) for mag, theta, name in zip(magnitudes, thetas, names): x = [] y = [] for m, t in zip(mag, theta): t = self.theta_from_value(t) r = self.magnitude_from_value(m, (m_scale[0], m_scale[-1])) * radius x.append(xmul * numpy.cos(t) * r + center[0]) y.append(ymul * numpy.sin(t) * r + center[1]) if template.legend.priority > 0 and name is not None: y_offset = len(labels.x) / float(label_count) * (template.legend.y2 - template.legend.y1) lx, ly = template.legend.x1, template.legend.y1 + y_offset x.append(lx) y.append(ly) labels.x.append(lx + .01) labels.y.append(ly) labels.string.append(str(name)) values.x.append(x) values.y.append(y) if template.legend.priority > 0: canvas.plot(labels, **plot_kwargs) del vcs.elements["textcombined"][labels.name] if self.draw_lines: canvas.plot(line, **plot_kwargs) del vcs.elements["line"][line.name] for el in self.to_cleanup: if vcs.istexttable(el): if el.name in vcs.elements["texttable"]: del vcs.elements["texttable"][el.name] else: if el.name in vcs.elements["textorientation"]: del vcs.elements["textorientation"][el.name] self.to_cleanup = [] # Prune unneeded levels from values to_prune = [] for ind, (x, y) in enumerate(zip(values.x, values.y)): if x and y: continue else: to_prune.append(ind) for prune_ind in to_prune[::-1]: del values.x[prune_ind] del values.y[prune_ind] if len(values.color) > prune_ind and len(values.color) > 1: del values.color[prune_ind] if len(values.size) > prune_ind and len(values.size) > 1: del values.size[prune_ind] if len(values.type) > prune_ind and len(values.type) > 1: del values.type[prune_ind] canvas.plot(values, bg=bg, donotstoredisplay=True) del vcs.elements["marker"][values.name] return canvas
saved_id = tas.id # Make sure the data is bounded before averaging cdutil.setTimeBoundsMonthly(tas) var = cdutil.averager(tas(squeeze=1), axis="xy") var = cdutil.ANNUALCYCLE.climatology(var) var.id = saved_id variables.append(var) # Customize the lines used to draw the plots line = vcs.createline() line.width = 2 line.color = ["red", "blue", "salmon", "medium aquamarine", "orange", "chartreuse"] line.type = ["dot", "dash", "dash-dot", "long-dash", "solid", "dash"] # Customize the markers drawn marker = vcs.createmarker() marker.size = 6 # You can just use the same colors as the lines marker.color = line.color marker.type = ["triangle_up", "plus", "diamond", "circle", "cross", "triangle_down"] # Middle of the month (from the time axis) months = { 15.5: "Jan", 45.0: "Feb", 74.5: "March", 105.0: "April", 135.5: "May", 166.0: "June", 196.5: "July", 227.5: "Aug",
import numpy with open("data/geolocate_activity.json") as f: geo_data = json.load(f) template = vcs.createtemplate() template.blank() template.data.priority = 1 template.box1.priority = 1 template.xtic1.priority = 1 template.ytic1.priority = 1 template.xlabel1.priority = 1 template.ylabel1.priority = 1 base_marker = vcs.createmarker() base_marker.worldcoordinate = [-180, 180, -90, 90] base_marker.viewport = [template.data.x1, template.data.x2, template.data.y1, template.data.y2] max_count = 0 for p in geo_data: max_count = max(p["count"], max_count) markers = { } zeroes = cdms2.MV2.ones((180, 360)) lon = cdms2.createAxis(numpy.arange(-180, 180, 1), id="lon") lat = cdms2.createAxis(numpy.arange(-90, 90, 1), id="lat") zeroes.setAxis(1, lon) zeroes.setAxis(0, lat)