CMS 3D CMS Logo

Classes | Functions | Variables
svgfig Namespace Reference

Classes

class  Axes
 
class  Curve
 
class  CurveAxis
 
class  Dots
 
class  Ellipse
 
class  Fig
 
class  Frame
 
class  Grid
 
class  HGrid
 
class  HLine
 
class  Line
 
class  LineAxis
 
class  LineGlobal
 
class  Path
 
class  Plot
 
class  Poly
 
class  Rect
 
class  SVG
 
class  Text
 
class  TextGlobal
 
class  Ticks
 
class  VGrid
 
class  VLine
 
class  XAxis
 
class  XErrorBars
 
class  YAxis
 
class  YErrorBars
 

Functions

def attr_preprocess (attr)
 
def canvas (sub, attr)
 
def canvas_outline (sub, attr)
 
def funcRtoC (expr, var="t", globals=None, locals=None)
 
def funcRtoR (expr, var="x", globals=None, locals=None)
 
def funcRtoR2 (expr, var="t", globals=None, locals=None)
 
def load (fileName)
 
def load_stream (stream)
 
def make_marker (id, shape, attr)
 
def make_symbol (id, shape="dot", attr)
 
def pathtoPath (svg)
 
def rgb (r, g, b, maximum=1.)
 
def rotate (angle, cx=0, cy=0)
 
def template (fileName, svg, replaceme="REPLACEME")
 
def totrans (expr, vars=("x","y"), globals=None, locals=None)
 
def unumber (x)
 
def window (xmin, xmax, ymin, ymax, x=0, y=0, width=100, height=100, xlogbase=None, ylogbase=None, minusInfinity=-1000, flipx=False, flipy=True)
 

Variables

dictionary _canvas_defaults
 
 _circular_dot = make_symbol("circular_dot")
 
 _default_directory
 
string _default_fileName = "tmp.svg"
 
int _epsilon = 1
 
dictionary _hacks = {}
 
dictionary _marker_templates
 
dictionary _symbol_templates
 
 all_whitespace
 
 output
 
 stack
 

Function Documentation

def svgfig.attr_preprocess (   attr)

Definition at line 46 of file svgfig.py.

Referenced by make_marker(), and make_symbol().

46 def attr_preprocess(attr):
47  for name in attr.keys():
48  name_colon = re.sub("__", ":", name)
49  if name_colon != name:
50  attr[name_colon] = attr[name]
51  del attr[name]
52  name = name_colon
53 
54  name_dash = re.sub("_", "-", name)
55  if name_dash != name:
56  attr[name_dash] = attr[name]
57  del attr[name]
58  name = name_dash
59 
60  return attr
61 
def attr_preprocess(attr)
Definition: svgfig.py:46
def svgfig.canvas (   sub,
  attr 
)
Creates a top-level SVG object, allowing the user to control the
image size and aspect ratio.

canvas(sub, sub, sub..., attribute=value)

sub                     optional list       nested SVG elements or text/Unicode
attribute=value pairs   optional keywords   SVG attributes

Default attribute values:

width           "400px"
height          "400px"
viewBox         "0 0 100 100"
xmlns           "http://www.w3.org/2000/svg"
xmlns:xlink     "http://www.w3.org/1999/xlink"
version         "1.1"
style           "stroke:black; fill:none; stroke-width:0.5pt; stroke-linejoin:round; text-anchor:middle"
font-family     "Helvetica,Arial,FreeSans?,Sans,sans,sans-serif"

Definition at line 481 of file svgfig.py.

References cmsPerfStripChart.dict.

Referenced by canvas_outline(), SiStripHistoPlotter.createStaticPlot(), TrackingMaterialPlotter.draw(), HcalObjRepresent::ADataRepr.draw(), DTOccupancyClusterBuilder.drawClusters(), ErrorsAnalyzer.drawHistograms(), ErrorsPropagationAnalyzer.drawHistograms(), TauDQMHistPlotter.endRun(), identity(), EcalDisplaysByEvent.init2DEcalCanvas(), main(), SiStripHistoPlotter.makeCondDBPlots(), TagProbeFitter.makeEfficiencyPlot1D(), TagProbeFitter.makeEfficiencyPlot2D(), SiStripHistoPlotter.makePlot(), MuScleFitUtils.minimizeLikelihood(), root.plotTF1(), ListGroups.produceAndSaveSummaryPlot(), SoftLeptonTagPlotter.psPlot(), IPTagPlotter< Container, Base >.psPlot(), TrackCountingTagPlotter.psPlot(), TrackProbabilityTagPlotter.psPlot(), JetTagPlotter.psPlot(), TagProbeFitter.saveDistributionsPlot(), TagProbeFitter.saveFitPlot(), MaterialAccountingGroup.savePlot(), svgfig.SVG.standalone_xml(), tfwliteselectortest::ThingsTSelector.terminate(), tfwliteselectortest::ThingsTSelector2.terminate(), examples::TrackAnalysisAlgorithm.terminate(), __class__< T >.terminate(), HFunctionResolution.Write(), HCovarianceVSxy.Write(), TestCorrection.~TestCorrection(), and TestResolution.~TestResolution().

481 def canvas(*sub, **attr):
482  """Creates a top-level SVG object, allowing the user to control the
483  image size and aspect ratio.
484 
485  canvas(sub, sub, sub..., attribute=value)
486 
487  sub optional list nested SVG elements or text/Unicode
488  attribute=value pairs optional keywords SVG attributes
489 
490  Default attribute values:
491 
492  width "400px"
493  height "400px"
494  viewBox "0 0 100 100"
495  xmlns "http://www.w3.org/2000/svg"
496  xmlns:xlink "http://www.w3.org/1999/xlink"
497  version "1.1"
498  style "stroke:black; fill:none; stroke-width:0.5pt; stroke-linejoin:round; text-anchor:middle"
499  font-family "Helvetica,Arial,FreeSans?,Sans,sans,sans-serif"
500  """
501  attributes = dict(_canvas_defaults)
502  attributes.update(attr)
503 
504  if sub == None or sub == ():
505  return SVG("svg", **attributes)
506  else:
507  return SVG("svg", *sub, **attributes)
508 
def canvas(sub, attr)
Definition: svgfig.py:481
def svgfig.canvas_outline (   sub,
  attr 
)
Same as canvas(), but draws an outline around the drawable area,
so that you know how close your image is to the edges.

Definition at line 509 of file svgfig.py.

References canvas(), and objects.autophobj.float.

509 def canvas_outline(*sub, **attr):
510  """Same as canvas(), but draws an outline around the drawable area,
511  so that you know how close your image is to the edges."""
512  svg = canvas(*sub, **attr)
513  match = re.match("[, \t]*([0-9e.+\-]+)[, \t]+([0-9e.+\-]+)[, \t]+([0-9e.+\-]+)[, \t]+([0-9e.+\-]+)[, \t]*", svg["viewBox"])
514  if match == None: raise ValueError("canvas viewBox is incorrectly formatted")
515  x, y, width, height = [float(x) for x in match.groups()]
516  svg.prepend(SVG("rect", x=x, y=y, width=width, height=height, stroke="none", fill="cornsilk"))
517  svg.append(SVG("rect", x=x, y=y, width=width, height=height, stroke="black", fill="none"))
518  return svg
519 
def canvas_outline(sub, attr)
Definition: svgfig.py:509
def canvas(sub, attr)
Definition: svgfig.py:481
def svgfig.funcRtoC (   expr,
  var = "t",
  globals = None,
  locals = None 
)
Converts a complex "z(t)" string to a function acceptable for Curve.

expr    required        string in the form "z(t)"
var     default="t"   name of the independent variable
globals default=None    dict of global variables used in the expression;
                        you may want to use Python's builtin globals()
locals  default=None    dict of local variables

Definition at line 1451 of file svgfig.py.

References output, and split.

1451 def funcRtoC(expr, var="t", globals=None, locals=None):
1452  """Converts a complex "z(t)" string to a function acceptable for Curve.
1453 
1454  expr required string in the form "z(t)"
1455  var default="t" name of the independent variable
1456  globals default=None dict of global variables used in the expression;
1457  you may want to use Python's builtin globals()
1458  locals default=None dict of local variables
1459  """
1460  g = cmath.__dict__
1461  if globals != None: g.update(globals)
1462  output = eval("lambda %s: (%s)" % (var, expr), g, locals)
1463  split = lambda z: (z.real, z.imag)
1464  output2 = lambda t: split(output(t))
1465  output2.__name__ = "%s -> %s" % (var, expr)
1466  return output2
1467 
def funcRtoC(expr, var="t", globals=None, locals=None)
Definition: svgfig.py:1451
double split
Definition: MVATrainer.cc:139
output
Definition: svgfig.py:559
def svgfig.funcRtoR (   expr,
  var = "x",
  globals = None,
  locals = None 
)
Converts a "f(x)" string to a function acceptable for Curve.

expr    required        string in the form "f(x)"
var     default="x"   name of the independent variable
globals default=None    dict of global variables used in the expression;
                        you may want to use Python's builtin globals()
locals  default=None    dict of local variables

Definition at line 1483 of file svgfig.py.

1483 def funcRtoR(expr, var="x", globals=None, locals=None):
1484  """Converts a "f(x)" string to a function acceptable for Curve.
1485 
1486  expr required string in the form "f(x)"
1487  var default="x" name of the independent variable
1488  globals default=None dict of global variables used in the expression;
1489  you may want to use Python's builtin globals()
1490  locals default=None dict of local variables
1491  """
1492  g = math.__dict__
1493  if globals != None: g.update(globals)
1494  output = eval("lambda %s: (%s, %s)" % (var, var, expr), g, locals)
1495  output.__name__ = "%s -> %s" % (var, expr)
1496  return output
1497 
def funcRtoR(expr, var="x", globals=None, locals=None)
Definition: svgfig.py:1483
def svgfig.funcRtoR2 (   expr,
  var = "t",
  globals = None,
  locals = None 
)
Converts a "f(t), g(t)" string to a function acceptable for Curve.

expr    required        string in the form "f(t), g(t)"
var     default="t"   name of the independent variable
globals default=None    dict of global variables used in the expression;
                        you may want to use Python's builtin globals()
locals  default=None    dict of local variables

Definition at line 1468 of file svgfig.py.

Referenced by svgfig.Curve.Path().

1468 def funcRtoR2(expr, var="t", globals=None, locals=None):
1469  """Converts a "f(t), g(t)" string to a function acceptable for Curve.
1470 
1471  expr required string in the form "f(t), g(t)"
1472  var default="t" name of the independent variable
1473  globals default=None dict of global variables used in the expression;
1474  you may want to use Python's builtin globals()
1475  locals default=None dict of local variables
1476  """
1477  g = math.__dict__
1478  if globals != None: g.update(globals)
1479  output = eval("lambda %s: (%s)" % (var, expr), g, locals)
1480  output.__name__ = "%s -> %s" % (var, expr)
1481  return output
1482 
def funcRtoR2(expr, var="t", globals=None, locals=None)
Definition: svgfig.py:1468
def svgfig.load (   fileName)
Loads an SVG image from a file.

Definition at line 546 of file svgfig.py.

References FrontierConditions_GlobalTag_cff.file, and load_stream().

Referenced by EcalDeadChannelRecoveryNN< DetIdT >.EcalDeadChannelRecoveryNN(), l1t::MP7BufferDumpToRaw.formatAMC(), FWPartialConfigLoadGUI.FWPartialConfigLoadGUI(), MonitorXMLParser.getDB_ME(), dqmservices::DQMProtobufReader.getNextItemType(), CovarianceParameterization.loadedVersion(), FedRawDataInputSource.nextEvent(), l1t::stage1::MissEtPacker.pack(), l1t::stage2::GlobalExtBlkPacker.pack(), l1t::stage1::MissHtPacker.pack(), l1t::stage1::RCTEmRegionPacker.pack(), l1t::stage2::CaloTowerPacker.pack(), l1t::stage2::GlobalAlgBlkPacker.pack(), l1t::stage1::CaloSpareHFPacker.pack(), l1t::stage1::EtSumPacker.pack(), l1t::stage1::HFRingPacker.pack(), l1t::stage2::EtSumPacker.pack(), l1t::stage2::CaloLayer1Packer.pack(), amc13::Packet.Packet(), amc::Packet.Packet(), dqmservices::DQMStreamerReader.prepareNextFile(), process(), l1t::L1TDigiToRaw.produce(), L1MuDTExtrapolationUnit.run(), L1MuBMExtrapolationUnit.run(), utils.unpickler.run(), MP7PacketReader.size(), MP7FileReader.size(), template(), and cscdqm::Configuration.~Configuration().

546 def load(fileName):
547  """Loads an SVG image from a file."""
548  return load_stream(file(fileName))
549 
def load_stream(stream)
Definition: svgfig.py:550
def load(fileName)
Definition: svgfig.py:546
def svgfig.load_stream (   stream)
Loads an SVG image from a stream (can be a string or a file object).

Definition at line 550 of file svgfig.py.

Referenced by load().

550 def load_stream(stream):
551  """Loads an SVG image from a stream (can be a string or a file object)."""
552 
553  from xml.sax import handler, make_parser
554  from xml.sax.handler import feature_namespaces, feature_external_ges, feature_external_pes
555 
556  class ContentHandler(handler.ContentHandler):
557  def __init__(self):
558  self.stack = []
559  self.output = None
560  self.all_whitespace = re.compile("^\s*$")
561 
562  def startElement(self, name, attr):
563  s = SVG(name)
564  s.attr = dict(attr.items())
565  if len(self.stack) > 0:
566  last = self.stack[-1]
567  last.sub.append(s)
568  self.stack.append(s)
569 
570  def characters(self, ch):
571  if not isinstance(ch, str) or self.all_whitespace.match(ch) == None:
572  if len(self.stack) > 0:
573  last = self.stack[-1]
574  if len(last.sub) > 0 and isinstance(last.sub[-1], str):
575  last.sub[-1] = last.sub[-1] + "\n" + ch
576  else:
577  last.sub.append(ch)
578 
579  def endElement(self, name):
580  if len(self.stack) > 0:
581  last = self.stack[-1]
582  if isinstance(last, SVG) and last.t == "style" and "type" in last.attr and last.attr["type"] == "text/css" and len(last.sub) == 1 and isinstance(last.sub[0], str):
583  last.sub[0] = "<![CDATA[\n" + last.sub[0] + "]]>"
584 
585  self.output = self.stack.pop()
586 
587  ch = ContentHandler()
588  parser = make_parser()
589  parser.setContentHandler(ch)
590  parser.setFeature(feature_namespaces, 0)
591  parser.setFeature(feature_external_ges, 0)
592  parser.parse(stream)
593  return ch.output
594 
def load_stream(stream)
Definition: svgfig.py:550
def svgfig.make_marker (   id,
  shape,
  attr 
)
Creates a new instance of an SVG marker to avoid cross-linking objects.

id                     required         a new identifier (string/Unicode)
shape                  required         the shape name from _marker_templates
attribute=value list   keyword list     modify the SVG attributes of the new marker

Definition at line 1964 of file svgfig.py.

References attr_preprocess().

Referenced by svgfig.Line.SVG(), and svgfig.LineGlobal.SVG().

1964 def make_marker(id, shape, **attr):
1965  """Creates a new instance of an SVG marker to avoid cross-linking objects.
1966 
1967  id required a new identifier (string/Unicode)
1968  shape required the shape name from _marker_templates
1969  attribute=value list keyword list modify the SVG attributes of the new marker
1970  """
1971  output = copy.deepcopy(_marker_templates[shape])
1972  for i in output.sub: i.attr.update(attr_preprocess(attr))
1973  output["id"] = id
1974  return output
1975 
def make_marker(id, shape, attr)
Definition: svgfig.py:1964
def attr_preprocess(attr)
Definition: svgfig.py:46
def svgfig.make_symbol (   id,
  shape = "dot",
  attr 
)
Creates a new instance of an SVG symbol to avoid cross-linking objects.

id                    required         a new identifier (string/Unicode)
shape                 default="dot"  the shape name from _symbol_templates
attribute=value list  keyword list     modify the SVG attributes of the new symbol

Definition at line 1893 of file svgfig.py.

References attr_preprocess().

1893 def make_symbol(id, shape="dot", **attr):
1894  """Creates a new instance of an SVG symbol to avoid cross-linking objects.
1895 
1896  id required a new identifier (string/Unicode)
1897  shape default="dot" the shape name from _symbol_templates
1898  attribute=value list keyword list modify the SVG attributes of the new symbol
1899  """
1900  output = copy.deepcopy(_symbol_templates[shape])
1901  for i in output.sub: i.attr.update(attr_preprocess(attr))
1902  output["id"] = id
1903  return output
1904 
def attr_preprocess(attr)
Definition: svgfig.py:46
def make_symbol(id, shape="dot", attr)
Definition: svgfig.py:1893
def svgfig.pathtoPath (   svg)
Converts SVG("path", d="...") into Path(d=[...]).

Definition at line 1006 of file svgfig.py.

References cmsPerfStripChart.dict, and str.

Referenced by geometryDiffVisualization.draw_disk().

1006 def pathtoPath(svg):
1007  """Converts SVG("path", d="...") into Path(d=[...])."""
1008  if not isinstance(svg, SVG) or svg.t != "path":
1009  raise TypeError("Only SVG <path /> objects can be converted into Paths")
1010  attr = dict(svg.attr)
1011  d = attr["d"]
1012  del attr["d"]
1013  for key in attr.keys():
1014  if not isinstance(key, str):
1015  value = attr[key]
1016  del attr[key]
1017  attr[str(key)] = value
1018  return Path(d, **attr)
1019 
def pathtoPath(svg)
Definition: svgfig.py:1006
#define str(s)
def svgfig.rgb (   r,
  g,
  b,
  maximum = 1. 
)
Create an SVG color string "#xxyyzz" from r, g, and b.

r,g,b = 0 is black and r,g,b = maximum is white.

Definition at line 39 of file svgfig.py.

References SiStripPI.max, and min().

Referenced by cert_plot(), geometryDiffVisualization.csc_colors(), geometryDiffVisualization.dt_colors(), and RunInfoPI.reportSummaryMapPalette().

39 def rgb(r, g, b, maximum=1.):
40  """Create an SVG color string "#xxyyzz" from r, g, and b.
41 
42  r,g,b = 0 is black and r,g,b = maximum is white.
43  """
44  return "#%02x%02x%02x" % (max(0, min(r*255./maximum, 255)), max(0, min(g*255./maximum, 255)), max(0, min(b*255./maximum, 255)))
45 
T min(T a, T b)
Definition: MathUtil.h:58
def rgb(r, g, b, maximum=1.)
Definition: svgfig.py:39
def svgfig.rotate (   angle,
  cx = 0,
  cy = 0 
)
Creates and returns a coordinate transformation which rotates
around (cx,cy) by "angle" degrees.

Definition at line 704 of file svgfig.py.

Referenced by MagGeoBuilderFromDDD::bLayer.bLayer(), MagGeoBuilderFromDDD.build(), TkRotation< align::Scalar >.operator*(), CmsTrackerPhase2TPDiskBuilder.PhiPosNegSplit_innerOuter(), CmsTrackerPhase1DiskBuilder.PhiPosNegSplit_innerOuter(), DetPositioner.rotateGeomDet(), and SurveyPxbDicer.SurveyPxbDicer().

704 def rotate(angle, cx=0, cy=0):
705  """Creates and returns a coordinate transformation which rotates
706  around (cx,cy) by "angle" degrees."""
707  angle *= math.pi/180.
708  return lambda x, y: (cx + math.cos(angle)*(x - cx) - math.sin(angle)*(y - cy), cy + math.sin(angle)*(x - cx) + math.cos(angle)*(y - cy))
709 
def rotate(angle, cx=0, cy=0)
Definition: svgfig.py:704
def svgfig.template (   fileName,
  svg,
  replaceme = "REPLACEME" 
)
Loads an SVG image from a file, replacing instances of
<REPLACEME /> with a given svg object.

fileName         required                name of the template SVG
svg              required                SVG object for replacement
replaceme        default="REPLACEME"   fake SVG element to be replaced by the given object

>>> print load("template.svg")
None                 <svg (2 sub) style=u'stroke:black; fill:none; stroke-width:0.5pt; stroke-linejoi
[0]                      <rect height=u'100' width=u'100' stroke=u'none' y=u'0' x=u'0' fill=u'yellow'
[1]                      <REPLACEME />
>>> 
>>> print template("template.svg", SVG("circle", cx=50, cy=50, r=30))
None                 <svg (2 sub) style=u'stroke:black; fill:none; stroke-width:0.5pt; stroke-linejoi
[0]                      <rect height=u'100' width=u'100' stroke=u'none' y=u'0' x=u'0' fill=u'yellow'
[1]                      <circle cy=50 cx=50 r=30 />

Definition at line 520 of file svgfig.py.

References load().

Referenced by dd_error_scan(), GenericMVAComputer.eval(), reco::modules::ParameterAdapter< S >.fillPSetDescription(), findNameSpaces(), edm::refitem::GetRefPtrImpl< C, T, F, KEY >.getRefPtr_(), edm::refitem::GetRefPtrImpl< C, T, F, unsigned int >.getRefPtr_(), edm::WorkerMaker< T >.makeModule(), edm::RefProd< C >.operator*(), and edm::RefProd< C >.operator->().

520 def template(fileName, svg, replaceme="REPLACEME"):
521  """Loads an SVG image from a file, replacing instances of
522  <REPLACEME /> with a given svg object.
523 
524  fileName required name of the template SVG
525  svg required SVG object for replacement
526  replaceme default="REPLACEME" fake SVG element to be replaced by the given object
527 
528  >>> print load("template.svg")
529  None <svg (2 sub) style=u'stroke:black; fill:none; stroke-width:0.5pt; stroke-linejoi
530  [0] <rect height=u'100' width=u'100' stroke=u'none' y=u'0' x=u'0' fill=u'yellow'
531  [1] <REPLACEME />
532  >>>
533  >>> print template("template.svg", SVG("circle", cx=50, cy=50, r=30))
534  None <svg (2 sub) style=u'stroke:black; fill:none; stroke-width:0.5pt; stroke-linejoi
535  [0] <rect height=u'100' width=u'100' stroke=u'none' y=u'0' x=u'0' fill=u'yellow'
536  [1] <circle cy=50 cx=50 r=30 />
537  """
538  output = load(fileName)
539  for ti, s in output:
540  if isinstance(s, SVG) and s.t == replaceme:
541  output[ti] = svg
542  return output
543 
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:520
def load(fileName)
Definition: svgfig.py:546
def svgfig.totrans (   expr,
  vars = ("x", "y"),
  globals = None,
  locals = None 
)
Converts to a coordinate transformation (a function that accepts
two arguments and returns two values).

expr       required                  a string expression or a function
                                     of two real or one complex value
vars       default=("x", "y")    independent variable names;
                                     a singleton ("z",) is interpreted
                                     as complex
globals    default=None              dict of global variables
locals     default=None              dict of local variables

Definition at line 597 of file svgfig.py.

References jets_cff.expr, output, and split.

Referenced by svgfig.Ticks.orient_tickmark(), svgfig.Curve.Path(), svgfig.Poly.Path(), svgfig.Fig.SVG(), svgfig.Plot.SVG(), svgfig.Path.SVG(), svgfig.Text.SVG(), svgfig.Dots.SVG(), svgfig.LineGlobal.SVG(), svgfig.Ticks.SVG(), svgfig.XErrorBars.SVG(), and svgfig.YErrorBars.SVG().

597 def totrans(expr, vars=("x", "y"), globals=None, locals=None):
598  """Converts to a coordinate transformation (a function that accepts
599  two arguments and returns two values).
600 
601  expr required a string expression or a function
602  of two real or one complex value
603  vars default=("x", "y") independent variable names;
604  a singleton ("z",) is interpreted
605  as complex
606  globals default=None dict of global variables
607  locals default=None dict of local variables
608  """
609 
610  if callable(expr):
611  if expr.__code__.co_argcount == 2:
612  return expr
613 
614  elif expr.__code__.co_argcount == 1:
615  split = lambda z: (z.real, z.imag)
616  output = lambda x, y: split(expr(x + y*1j))
617  output.__name__ = expr.__name__
618  return output
619 
620  else:
621  raise TypeError("must be a function of 2 or 1 variables")
622 
623  if len(vars) == 2:
624  g = math.__dict__
625  if globals != None: g.update(globals)
626  output = eval("lambda %s, %s: (%s)" % (vars[0], vars[1], expr), g, locals)
627  output.__name__ = "%s,%s -> %s" % (vars[0], vars[1], expr)
628  return output
629 
630  elif len(vars) == 1:
631  g = cmath.__dict__
632  if globals != None: g.update(globals)
633  output = eval("lambda %s: (%s)" % (vars[0], expr), g, locals)
634  split = lambda z: (z.real, z.imag)
635  output2 = lambda x, y: split(output(x + y*1j))
636  output2.__name__ = "%s -> %s" % (vars[0], expr)
637  return output2
638 
639  else:
640  raise TypeError("vars must have 2 or 1 elements")
641 
double split
Definition: MVATrainer.cc:139
output
Definition: svgfig.py:559
def totrans(expr, vars=("x","y"), globals=None, locals=None)
Definition: svgfig.py:597
def svgfig.unumber (   x)
Converts numbers to a Unicode string, taking advantage of special
Unicode characters to make nice minus signs and scientific notation.

Definition at line 2283 of file svgfig.py.

2283 def unumber(x):
2284  """Converts numbers to a Unicode string, taking advantage of special
2285  Unicode characters to make nice minus signs and scientific notation.
2286  """
2287  output = u"%g" % x
2288 
2289  if output[0] == u"-":
2290  output = u"\u2013" + output[1:]
2291 
2292  index = output.find(u"e")
2293  if index != -1:
2294  uniout = unicode(output[:index]) + u"\u00d710"
2295  saw_nonzero = False
2296  for n in output[index+1:]:
2297  if n == u"+": pass # uniout += u"\u207a"
2298  elif n == u"-": uniout += u"\u207b"
2299  elif n == u"0":
2300  if saw_nonzero: uniout += u"\u2070"
2301  elif n == u"1":
2302  saw_nonzero = True
2303  uniout += u"\u00b9"
2304  elif n == u"2":
2305  saw_nonzero = True
2306  uniout += u"\u00b2"
2307  elif n == u"3":
2308  saw_nonzero = True
2309  uniout += u"\u00b3"
2310  elif u"4" <= n <= u"9":
2311  saw_nonzero = True
2312  if saw_nonzero: uniout += eval("u\"\\u%x\"" % (0x2070 + ord(n) - ord(u"0")))
2313  else: uniout += n
2314 
2315  if uniout[:2] == u"1\u00d7": uniout = uniout[2:]
2316  return uniout
2317 
2318  return output
2319 
def unumber(x)
Definition: svgfig.py:2283
def svgfig.window (   xmin,
  xmax,
  ymin,
  ymax,
  x = 0,
  y = 0,
  width = 100,
  height = 100,
  xlogbase = None,
  ylogbase = None,
  minusInfinity = -1000,
  flipx = False,
  flipy = True 
)
Creates and returns a coordinate transformation (a function that
accepts two arguments and returns two values) that transforms from
    (xmin, ymin), (xmax, ymax)
to
    (x, y), (x + width, y + height).

xlogbase, ylogbase    default=None, None     if a number, transform
                                             logarithmically with given base
minusInfinity         default=-1000          what to return if
                                             log(0 or negative) is attempted
flipx                 default=False          if true, reverse the direction of x
flipy                 default=True           if true, reverse the direction of y

(When composing windows, be sure to set flipy=False.)

Definition at line 642 of file svgfig.py.

Referenced by CompositeTECWedge.basicComponents(), TOBRod.basicComponents(), Phase2OTBarrelRod.basicComponents(), LocalCacheFile.cache(), CSCStripElectronicsSim.channelsToRead(), TOBRod.computeWindowSize(), Phase2OTBarrelRod.computeWindowSize(), TTStubAlgorithm_official< T >.degradeBend(), PixelForwardLayer.groupedCompatibleDetsV(), PixelForwardLayerPhase1.groupedCompatibleDetsV(), CompositeTECWedge.groupedCompatibleDetsV(), TBLayer.groupedCompatibleDetsV(), TIBRing.groupedCompatibleDetsV(), PixelBlade.groupedCompatibleDetsV(), TOBRod.groupedCompatibleDetsV(), Phase1PixelBlade.groupedCompatibleDetsV(), Phase2OTBarrelRod.groupedCompatibleDetsV(), CompositeTECPetal.groupedCompatibleDetsV(), TBLayer.isPhase2OT(), EcalDeadChannelRecoveryNN< EBDetId >.makeNxNMatrice_RelDC(), AlignmentMonitorMuonSystemMap1D::MuonSystemMapPlot1D.MuonSystemMapPlot1D(), TTStubAlgorithm_official< T >.PatternHitCorrelation(), MuonResidualsFitter.plotsimple(), MuonResidualsFitter.plotweighted(), TIDRing.specificSurface(), Phase2EndcapRing.specificSurface(), PixelBlade.specificSurface(), Phase1PixelBlade.specificSurface(), TECLayer.subDetector(), TBPLayer.TBPLayer(), and TTStubAlgorithm_official< T >.~TTStubAlgorithm_official().

642 def window(xmin, xmax, ymin, ymax, x=0, y=0, width=100, height=100, xlogbase=None, ylogbase=None, minusInfinity=-1000, flipx=False, flipy=True):
643  """Creates and returns a coordinate transformation (a function that
644  accepts two arguments and returns two values) that transforms from
645  (xmin, ymin), (xmax, ymax)
646  to
647  (x, y), (x + width, y + height).
648 
649  xlogbase, ylogbase default=None, None if a number, transform
650  logarithmically with given base
651  minusInfinity default=-1000 what to return if
652  log(0 or negative) is attempted
653  flipx default=False if true, reverse the direction of x
654  flipy default=True if true, reverse the direction of y
655 
656  (When composing windows, be sure to set flipy=False.)
657  """
658 
659  if flipx:
660  ox1 = x + width
661  ox2 = x
662  else:
663  ox1 = x
664  ox2 = x + width
665  if flipy:
666  oy1 = y + height
667  oy2 = y
668  else:
669  oy1 = y
670  oy2 = y + height
671  ix1 = xmin
672  iy1 = ymin
673  ix2 = xmax
674  iy2 = ymax
675 
676  if xlogbase != None and (ix1 <= 0. or ix2 <= 0.): raise ValueError("x range incompatible with log scaling: (%g, %g)" % (ix1, ix2))
677 
678  if ylogbase != None and (iy1 <= 0. or iy2 <= 0.): raise ValueError("y range incompatible with log scaling: (%g, %g)" % (iy1, iy2))
679 
680  def maybelog(t, it1, it2, ot1, ot2, logbase):
681  if t <= 0.: return minusInfinity
682  else:
683  return ot1 + 1.*(math.log(t, logbase) - math.log(it1, logbase))/(math.log(it2, logbase) - math.log(it1, logbase)) * (ot2 - ot1)
684 
685  xlogstr, ylogstr = "", ""
686 
687  if xlogbase == None:
688  xfunc = lambda x: ox1 + 1.*(x - ix1)/(ix2 - ix1) * (ox2 - ox1)
689  else:
690  xfunc = lambda x: maybelog(x, ix1, ix2, ox1, ox2, xlogbase)
691  xlogstr = " xlog=%g" % xlogbase
692 
693  if ylogbase == None:
694  yfunc = lambda y: oy1 + 1.*(y - iy1)/(iy2 - iy1) * (oy2 - oy1)
695  else:
696  yfunc = lambda y: maybelog(y, iy1, iy2, oy1, oy2, ylogbase)
697  ylogstr = " ylog=%g" % ylogbase
698 
699  output = lambda x, y: (xfunc(x), yfunc(y))
700 
701  output.__name__ = "(%g, %g), (%g, %g) -> (%g, %g), (%g, %g)%s%s" % (ix1, ix2, iy1, iy2, ox1, ox2, oy1, oy2, xlogstr, ylogstr)
702  return output
703 
def window(xmin, xmax, ymin, ymax, x=0, y=0, width=100, height=100, xlogbase=None, ylogbase=None, minusInfinity=-1000, flipx=False, flipy=True)
Definition: svgfig.py:642

Variable Documentation

dictionary svgfig._canvas_defaults
private
Initial value:
1 = {"width": "400px", "height": "400px", "viewBox": "0 0 100 100", \
2  "xmlns": "http://www.w3.org/2000/svg", "xmlns:xlink": "http://www.w3.org/1999/xlink", "version":"1.1", \
3  "style": {"stroke":"black", "fill":"none", "stroke-width":"0.5pt", "stroke-linejoin":"round", "text-anchor":"middle"}, \
4  "font-family": ["Helvetica", "Arial", "FreeSans", "Sans", "sans", "sans-serif"], \
5  }

Definition at line 475 of file svgfig.py.

svgfig._circular_dot = make_symbol("circular_dot")
private

Definition at line 1905 of file svgfig.py.

string svgfig._default_directory
private
Initial value:
1 = _winreg.QueryValueEx(_winreg.OpenKey(_winreg.HKEY_CURRENT_USER, \
2  r"Software\Microsoft\Windows\Current Version\Explorer\Shell Folders"), "Desktop")[0]

Definition at line 26 of file svgfig.py.

string svgfig._default_fileName = "tmp.svg"
private

Definition at line 34 of file svgfig.py.

int svgfig._epsilon = 1
private

Definition at line 20 of file svgfig.py.

dictionary svgfig._hacks = {}
private

Definition at line 36 of file svgfig.py.

dictionary svgfig._marker_templates
private
Initial value:
1 = {"arrow_start": SVG("marker", SVG("path", d="M 9 3.6 L 10.5 0 L 0 3.6 L 10.5 7.2 L 9 3.6 Z"), viewBox="0 0 10.5 7.2", refX="9", refY="3.6", markerWidth="10.5", markerHeight="7.2", markerUnits="strokeWidth", orient="auto", stroke="none", fill="black"), \
2  "arrow_end": SVG("marker", SVG("path", d="M 1.5 3.6 L 0 0 L 10.5 3.6 L 0 7.2 L 1.5 3.6 Z"), viewBox="0 0 10.5 7.2", refX="1.5", refY="3.6", markerWidth="10.5", markerHeight="7.2", markerUnits="strokeWidth", orient="auto", stroke="none", fill="black"), \
3  }

Definition at line 1960 of file svgfig.py.

dictionary svgfig._symbol_templates
private
Initial value:
1 = {"dot": SVG("symbol", SVG("circle", cx=0, cy=0, r=1, stroke="none", fill="black"), viewBox="0 0 1 1", overflow="visible"), \
2  "box": SVG("symbol", SVG("rect", x1=-1, y1=-1, x2=1, y2=1, stroke="none", fill="black"), viewBox="0 0 1 1", overflow="visible"), \
3  "uptri": SVG("symbol", SVG("path", d="M -1 0.866 L 1 0.866 L 0 -0.866 Z", stroke="none", fill="black"), viewBox="0 0 1 1", overflow="visible"), \
4  "downtri": SVG("symbol", SVG("path", d="M -1 -0.866 L 1 -0.866 L 0 0.866 Z", stroke="none", fill="black"), viewBox="0 0 1 1", overflow="visible"), \
5  }

Definition at line 1887 of file svgfig.py.

svgfig.all_whitespace

Definition at line 560 of file svgfig.py.

svgfig.output

Definition at line 559 of file svgfig.py.

Referenced by funcRtoC(), and totrans().

svgfig.stack