def __init__(self, A, B, C,**options): """ Initialize HyperbolicTriangle under the map (z-z0)/(z-\bar(z0)): Examples:: sage: from sage.plot.hyperbolic_triangle import HyperbolicTriangle sage: print HyperbolicTriangle(0, 1/2, I, {}) Hyperbolic triangle (0.000000000000000, 0.500000000000000, 1.00000000000000*I) """ A, B, C = (CC(A), CC(B), CC(C)) self.path = [] self._graphics = Graphics() Z0 = options['center'] #.get('center',C(0,1)) self._z0=CC(Z0); self._z0bar=CC(Z0).conjugate() self._hyperbolic_arc_d(A, B, True); self._hyperbolic_arc_d(B, C); self._hyperbolic_arc_d(C, A); #BezierPath.__init__(self, self.path, options) options.pop('center',None) if options=={} or options==None: self._options = {} else: self._options = options #super(HyperbolicTriangleDisc,self).__init__(options) self.A, self.B, self.C = (A, B, C)
def my_hyperbolic_triangle(a, b, c, **options): """ Return a hyperbolic triangle in the complex hyperbolic plane with points (a, b, c). Type ``?hyperbolic_triangle`` to see all options. INPUT: - ``a, b, c`` - complex numbers in the upper half complex plane OPTIONS: - ``alpha`` - default: 1 - ``fill`` - default: False - ``thickness`` - default: 1 - ``rgbcolor`` - default: 'blue' - ``linestyle`` - default: 'solid' EXAMPLES: Show a hyperbolic triangle with coordinates 0, `1/2+i\sqrt{3}/2` and `-1/2+i\sqrt{3}/2`:: sage: hyperbolic_triangle(0, -1/2+I*sqrt(3)/2, 1/2+I*sqrt(3)/2) A hyperbolic triangle with coordinates 0, 1 and 2+i:: sage: hyperbolic_triangle(0, 1, 2+i, fill=true, rgbcolor='red') """ from sage.plot.all import Graphics g = Graphics() g._set_extra_kwds(g._extract_kwds_for_show(options)) model = options['model'] npts = options.get('npts',10) sides = options.pop('sides',[1,2,3]) ## Which of the sides we will draw. verbose = options.get('verbose',0) options.pop('model',None); options.pop('method',None) if model=="D": #g.add_primitive(HyperbolicTriangleDisc(a, b, c, **options)) #print "options=",options options['sides']=sides H = HyperbolicTriangleDisc(a, b, c, **options) g += H() else: options.pop('npts',None) if sides == [1,2,3]: if verbose>0: print "adding HyperbolicTriangle({0}, {1}, {2},options={3})".format(a,b,c,options) options.pop('verbose',0) g.add_primitive(HyperbolicTriangle(a, b, c, options)) else: options['sides']=sides if verbose>0: print "adding MyHyperbolicTriangle({0}, {1}, {2},options={3})".format(a,b,c,options) g.add_primitive(MyHyperbolicTriangle(a, b, c, options)) g.set_aspect_ratio(1) return g
def __init__(self, A, B, C, options): """ Initialize HyperbolicTriangle: Examples:: sage: from sage.plot.hyperbolic_triangle import HyperbolicTriangle sage: print HyperbolicTriangle(0, 1/2, I, {}) Hyperbolic triangle (0.000000000000000, 0.500000000000000, 1.00000000000000*I) """ A, B, C = (CC(A), CC(B), CC(C)) self.path = [] sides = options.pop('sides',[1,2,3]) verbose=options.pop('verbose',0) sides.sort() if sides == [1]: if verbose>0: print "Drawing A - B!" self._hyperbolic_arc(A, B, True); elif sides == [2]: if verbose>0: print "Drawing B - C!" self._hyperbolic_arc(B, C, True); elif sides == [3]: if verbose>0: print "Drawing C - A!" self._hyperbolic_arc(C, A, True); elif sides == [1,2]: if verbose>0: print "Drawing A - B! & B - C!" self._hyperbolic_arc(A, B, True); self._hyperbolic_arc(B, C, False); elif sides == [1,3]: if verbose>0: print "Drawing C - A! & A - B" self._hyperbolic_arc(C, A,True) self._hyperbolic_arc(A, B, False) elif sides == [2,3]: if verbose>0: print "Drawing B - C! & C - A" self._hyperbolic_arc(B, C,True) self._hyperbolic_arc(C, A, False) else: self._hyperbolic_arc(A, B,True) self._hyperbolic_arc(B, C,False) self._hyperbolic_arc(C, A, False) BezierPath.__init__(self, self.path, options) self.A, self.B, self.C = (A, B, C) self._pts = [A,B,C]
def __init__(self, A, B, C, options): """ Initialize HyperbolicTriangle: Examples:: sage: from sage.plot.hyperbolic_triangle import HyperbolicTriangle sage: print HyperbolicTriangle(0, 1/2, I, {}) Hyperbolic triangle (0.000000000000000, 0.500000000000000, 1.00000000000000*I) """ A, B, C = (CC(A), CC(B), CC(C)) self.path = [] sides = options.pop('sides', [1, 2, 3]) verbose = options.pop('verbose', 0) sides.sort() if sides == [1]: if verbose > 0: print "Drawing A - B!" self._hyperbolic_arc(A, B, True) elif sides == [2]: if verbose > 0: print "Drawing B - C!" self._hyperbolic_arc(B, C, True) elif sides == [3]: if verbose > 0: print "Drawing C - A!" self._hyperbolic_arc(C, A, True) elif sides == [1, 2]: if verbose > 0: print "Drawing A - B! & B - C!" self._hyperbolic_arc(A, B, True) self._hyperbolic_arc(B, C, False) elif sides == [1, 3]: if verbose > 0: print "Drawing C - A! & A - B" self._hyperbolic_arc(C, A, True) self._hyperbolic_arc(A, B, False) elif sides == [2, 3]: if verbose > 0: print "Drawing B - C! & C - A" self._hyperbolic_arc(B, C, True) self._hyperbolic_arc(C, A, False) else: self._hyperbolic_arc(A, B, True) self._hyperbolic_arc(B, C, False) self._hyperbolic_arc(C, A, False) BezierPath.__init__(self, self.path, options) self.A, self.B, self.C = (A, B, C) self._pts = [A, B, C]
def _render_on_subplot(self, subplot): """ Render this ellipse in a subplot. This is the key function that defines how this ellipse graphics primitive is rendered in matplotlib's library. TESTS:: sage: ellipse((0,0),3,1,pi/6,fill=True,alpha=0.3) :: sage: ellipse((3,2),1,2) """ import matplotlib.patches as patches options = self.options() p = patches.Ellipse( (self.x,self.y), self.r1*2.,self.r2*2.,self.angle/pi*180.) p.set_linewidth(float(options['thickness'])) p.set_fill(options['fill']) a = float(options['alpha']) p.set_alpha(a) ec = to_mpl_color(options['edgecolor']) fc = to_mpl_color(options['facecolor']) if 'rgbcolor' in options: ec = fc = to_mpl_color(options['rgbcolor']) p.set_edgecolor(ec) p.set_facecolor(fc) p.set_linestyle(options['linestyle']) z = int(options.pop('zorder', 0)) p.set_zorder(z) subplot.add_patch(p)
def _render_on_subplot(self, subplot): """ TESTS:: sage: A = arc((1,1),3,4,pi/4,(pi,4*pi/3)); A Graphics object consisting of 1 graphics primitive """ import matplotlib.patches as patches from sage.plot.misc import get_matplotlib_linestyle options = self.options() p = patches.Arc( (self.x,self.y), 2.*self.r1, 2.*self.r2, fmod(self.angle,2*pi)*(180./pi), self.s1*(180./pi), self.s2*(180./pi)) p.set_linewidth(float(options['thickness'])) a = float(options['alpha']) p.set_alpha(a) z = int(options.pop('zorder',1)) p.set_zorder(z) c = to_mpl_color(options['rgbcolor']) p.set_linestyle(get_matplotlib_linestyle(options['linestyle'],return_type='long')) p.set_edgecolor(c) subplot.add_patch(p)
def _render_on_subplot(self, subplot): """ Render this ellipse in a subplot. This is the key function that defines how this ellipse graphics primitive is rendered in matplotlib's library. TESTS:: sage: ellipse((0,0),3,1,pi/6,fill=True,alpha=0.3) :: sage: ellipse((3,2),1,2) """ import matplotlib.patches as patches options = self.options() p = patches.Ellipse((self.x, self.y), self.r1 * 2., self.r2 * 2., self.angle / pi * 180.) p.set_linewidth(float(options['thickness'])) p.set_fill(options['fill']) a = float(options['alpha']) p.set_alpha(a) ec = to_mpl_color(options['edgecolor']) fc = to_mpl_color(options['facecolor']) if 'rgbcolor' in options: ec = fc = to_mpl_color(options['rgbcolor']) p.set_edgecolor(ec) p.set_facecolor(fc) p.set_linestyle(options['linestyle']) p.set_label(options['legend_label']) z = int(options.pop('zorder', 0)) p.set_zorder(z) subplot.add_patch(p)
def _render_on_subplot(self, subplot): """ TESTS:: sage: A = arc((1,1),3,4,pi/4,(pi,4*pi/3)); A """ import matplotlib.patches as patches options = self.options() p = patches.Arc( (self.x,self.y), 2.*self.r1, 2.*self.r2, fmod(self.angle,2*pi)*(180./pi), self.s1*(180./pi), self.s2*(180./pi)) p.set_linewidth(float(options['thickness'])) a = float(options['alpha']) p.set_alpha(a) z = int(options.pop('zorder',1)) p.set_zorder(z) c = to_mpl_color(options['rgbcolor']) p.set_linestyle(options['linestyle']) p.set_edgecolor(c) subplot.add_patch(p)
def get_minmax_data(self): """ Get minimum and maximum horizontal and vertical ranges for the Histogram object. EXAMPLES:: sage: H = histogram([10,3,5], normed=True); h = H[0] sage: h.get_minmax_data() {'xmax': 10.0, 'xmin': 3.0, 'ymax': 0.4761904761904765, 'ymin': 0} sage: G = histogram([random() for _ in range(500)]); g = G[0] sage: g.get_minmax_data() # random output {'xmax': 0.99729312925213209, 'xmin': 0.00013024562219410285, 'ymax': 61, 'ymin': 0} sage: Y = histogram([random()*10 for _ in range(500)], range=[2,8]); y = Y[0] sage: ymm = y.get_minmax_data(); ymm['xmax'], ymm['xmin'] (8.0, 2.0) sage: Z = histogram([[1,3,2,0], [4,4,3,3]]); z = Z[0] sage: z.get_minmax_data() {'xmax': 4.0, 'xmin': 0, 'ymax': 2, 'ymin': 0} """ import numpy options=self.options() opt=dict(range = options.pop('range',None), bins = options.pop('bins',None), normed = options.pop('normed',None), weights = options.pop('weights', None)) #check to see if a list of datasets if not hasattr(self.datalist[0],'__contains__' ): ydata,xdata=numpy.histogram(self.datalist, **opt) return minmax_data(xdata,[0]+list(ydata), dict=True) else: m = { 'xmax': 0, 'xmin':0, 'ymax':0, 'ymin':0} if not options.pop('stacked',None): for d in self.datalist: ydata, xdata = numpy.histogram(d,**opt) m['xmax'] = max([m['xmax']] + list(xdata)) m['xmin'] = min([m['xmin']] + list(xdata)) m['ymax'] = max([m['ymax']] + list(ydata)) return m else: for d in self.datalist: ydata, xdata = numpy.histogram(d,**opt) m['xmax'] = max([m['xmax']] + list(xdata)) m['xmin'] = min([m['xmin']] + list(xdata)) m['ymax'] = m['ymax'] + max(list(ydata)) return m
def my_hyperbolic_triangle(a, b, c, **options): """ Return a hyperbolic triangle in the complex hyperbolic plane with points (a, b, c). Type ``?hyperbolic_triangle`` to see all options. INPUT: - ``a, b, c`` - complex numbers in the upper half complex plane OPTIONS: - ``alpha`` - default: 1 - ``fill`` - default: False - ``thickness`` - default: 1 - ``rgbcolor`` - default: 'blue' - ``linestyle`` - default: 'solid' EXAMPLES: Show a hyperbolic triangle with coordinates 0, `1/2+i\sqrt{3}/2` and `-1/2+i\sqrt{3}/2`:: sage: hyperbolic_triangle(0, -1/2+I*sqrt(3)/2, 1/2+I*sqrt(3)/2) A hyperbolic triangle with coordinates 0, 1 and 2+i:: sage: hyperbolic_triangle(0, 1, 2+i, fill=true, rgbcolor='red') """ from sage.plot.all import Graphics g = Graphics() g._set_extra_kwds(g._extract_kwds_for_show(options)) model = options['model'] options.pop('model',None); options.pop('method',None) if model=="D": #g.add_primitive(HyperbolicTriangleDisc(a, b, c, **options)) H = HyperbolicTriangleDisc(a, b, c, **options) g += H() else: g.add_primitive(HyperbolicTriangle(a, b, c, options)) g.set_aspect_ratio(1) return g
def _render_on_subplot(self, subplot): """ TESTS:: sage: A = arc((1,1),3,4,pi/4,(pi,4*pi/3)); A Graphics object consisting of 1 graphics primitive """ from sage.plot.misc import get_matplotlib_linestyle options = self.options() p = self._matplotlib_arc() p.set_linewidth(float(options['thickness'])) a = float(options['alpha']) p.set_alpha(a) z = int(options.pop('zorder', 1)) p.set_zorder(z) c = to_mpl_color(options['rgbcolor']) p.set_linestyle(get_matplotlib_linestyle(options['linestyle'], return_type='long')) p.set_edgecolor(c) subplot.add_patch(p)
def _render_on_subplot(self, subplot): """ TESTS:: sage: A = arc((1,1),3,4,pi/4,(pi,4*pi/3)); A Graphics object consisting of 1 graphics primitive """ from sage.plot.misc import get_matplotlib_linestyle options = self.options() p = self._matplotlib_arc() p.set_linewidth(float(options['thickness'])) a = float(options['alpha']) p.set_alpha(a) z = int(options.pop('zorder', 1)) p.set_zorder(z) c = to_mpl_color(options['rgbcolor']) p.set_linestyle( get_matplotlib_linestyle(options['linestyle'], return_type='long')) p.set_edgecolor(c) subplot.add_patch(p)
def _render_on_subplot(self, subplot): """ Render this ellipse in a subplot. This is the key function that defines how this ellipse graphics primitive is rendered in matplotlib's library. TESTS:: sage: ellipse((0,0),3,1,pi/6,fill=True,alpha=0.3) Graphics object consisting of 1 graphics primitive :: sage: ellipse((3,2),1,2) Graphics object consisting of 1 graphics primitive """ import matplotlib.patches as patches from sage.plot.misc import get_matplotlib_linestyle options = self.options() p = patches.Ellipse((self.x, self.y), self.r1 * 2.0, self.r2 * 2.0, self.angle / pi * 180.0) p.set_linewidth(float(options["thickness"])) p.set_fill(options["fill"]) a = float(options["alpha"]) p.set_alpha(a) ec = to_mpl_color(options["edgecolor"]) fc = to_mpl_color(options["facecolor"]) if "rgbcolor" in options: ec = fc = to_mpl_color(options["rgbcolor"]) p.set_edgecolor(ec) p.set_facecolor(fc) p.set_linestyle(get_matplotlib_linestyle(options["linestyle"], return_type="long")) p.set_label(options["legend_label"]) z = int(options.pop("zorder", 0)) p.set_zorder(z) subplot.add_patch(p)
def my_hyperbolic_triangle(a, b, c, **options): """ Return a hyperbolic triangle in the complex hyperbolic plane with points (a, b, c). Type ``?hyperbolic_triangle`` to see all options. INPUT: - ``a, b, c`` - complex numbers in the upper half complex plane OPTIONS: - ``alpha`` - default: 1 - ``fill`` - default: False - ``thickness`` - default: 1 - ``rgbcolor`` - default: 'blue' - ``linestyle`` - default: 'solid' EXAMPLES: Show a hyperbolic triangle with coordinates 0, `1/2+i\sqrt{3}/2` and `-1/2+i\sqrt{3}/2`:: sage: hyperbolic_triangle(0, -1/2+I*sqrt(3)/2, 1/2+I*sqrt(3)/2) A hyperbolic triangle with coordinates 0, 1 and 2+i:: sage: hyperbolic_triangle(0, 1, 2+i, fill=true, rgbcolor='red') """ from sage.plot.all import Graphics g = Graphics() g._set_extra_kwds(g._extract_kwds_for_show(options)) model = options['model'] npts = options.get('npts', 10) sides = options.pop('sides', [1, 2, 3]) ## Which of the sides we will draw. verbose = options.get('verbose', 0) options.pop('model', None) options.pop('method', None) if model == "D": #g.add_primitive(HyperbolicTriangleDisc(a, b, c, **options)) #print "options=",options options['sides'] = sides H = HyperbolicTriangleDisc(a, b, c, **options) g += H() else: options.pop('npts', None) if sides == [1, 2, 3]: if verbose > 0: print "adding HyperbolicTriangle({0}, {1}, {2},options={3})".format( a, b, c, options) options.pop('verbose', 0) ## check if We need my class or the original class g.add_primitive(HyperbolicTriangle(a, b, c, options)) else: options['sides'] = sides if verbose > 0: print "adding HyperbolicTriangle({0}, {1}, {2},options={3})".format( a, b, c, options) g.add_primitive(HyperbolicTriangle(a, b, c, options)) g.set_aspect_ratio(1) return g
def __init__(self, A, B, C,**options): """ Initialize HyperbolicTriangle under the map (z-z0)/(z-\bar(z0)): Examples:: sage: from sage.plot.hyperbolic_triangle import HyperbolicTriangle sage: print HyperbolicTriangle(0, 1/2, I, {}) Hyperbolic triangle (0.000000000000000, 0.500000000000000, 1.00000000000000*I) """ A, B, C = (CC(A), CC(B), CC(C)) self.path = [] self._options = {} self._graphics = Graphics() self._verbose = options.pop('verbose',None) Z0 = options['center'] #.get('center',C(0,1)) options.pop('center',None) self._npts = options.pop('npts',10) sides = options.pop('sides',[1,2,3]) #options.pop('fill',None) self._options.update(options) self._z0=CC(Z0); self._z0bar=CC(Z0).conjugate() verbose=self._verbose sides.sort() if sides == [1]: if verbose>0: print "Drawing A - B!" self._hyperbolic_arc_d(A, B, True); elif sides == [2]: if verbose>0: print "Drawing B - C!" self._hyperbolic_arc_d(B, C, True); elif sides == [3]: if verbose>0: print "Drawing C - A!" self._hyperbolic_arc_d(C, A, True); elif sides == [1,2]: if verbose>0: print "Drawing A - B! & B - C!" self._hyperbolic_arc_d(A, B, True); self._hyperbolic_arc_d(B, C,False); elif sides == [1,3]: if verbose>0: print "Drawing C - A! & A - B" self._hyperbolic_arc_d(C, A,True) self._hyperbolic_arc_d(A, B, False) elif sides == [2,3]: if verbose>0: print "Drawing B - C! & C - A" self._hyperbolic_arc_d(B, C,True) self._hyperbolic_arc_d(C, A, False) else: self._hyperbolic_arc_d(A, B,True) self._hyperbolic_arc_d(B, C,False) self._hyperbolic_arc_d(C, A, False) #self._hyperbolic_arc_d(A, B, True); #self._hyperbolic_arc_d(B, C); #self._hyperbolic_arc_d(C, A); #BezierPath.__init__(self, self.path, options) #super(HyperbolicTriangleDisc,self).__init__(options) self.A, self.B, self.C = (A, B, C)
def __init__(self, A, B, C, **options): """ Initialize HyperbolicTriangle under the map (z-z0)/(z-\bar(z0)): Examples:: sage: from sage.plot.hyperbolic_triangle import HyperbolicTriangle sage: print HyperbolicTriangle(0, 1/2, I, {}) Hyperbolic triangle (0.000000000000000, 0.500000000000000, 1.00000000000000*I) """ A, B, C = (CC(A), CC(B), CC(C)) self.path = [] self._options = {} self._graphics = Graphics() self._verbose = options.pop('verbose', None) Z0 = options['center'] #.get('center',C(0,1)) options.pop('center', None) self._npts = options.pop('npts', 10) sides = options.pop('sides', [1, 2, 3]) #options.pop('fill',None) self._options.update(options) self._z0 = CC(Z0) self._z0bar = CC(Z0).conjugate() verbose = self._verbose sides.sort() if sides == [1]: if verbose > 0: print "Drawing A - B!" self._hyperbolic_arc_d(A, B, True) elif sides == [2]: if verbose > 0: print "Drawing B - C!" self._hyperbolic_arc_d(B, C, True) elif sides == [3]: if verbose > 0: print "Drawing C - A!" self._hyperbolic_arc_d(C, A, True) elif sides == [1, 2]: if verbose > 0: print "Drawing A - B! & B - C!" self._hyperbolic_arc_d(A, B, True) self._hyperbolic_arc_d(B, C, False) elif sides == [1, 3]: if verbose > 0: print "Drawing C - A! & A - B" self._hyperbolic_arc_d(C, A, True) self._hyperbolic_arc_d(A, B, False) elif sides == [2, 3]: if verbose > 0: print "Drawing B - C! & C - A" self._hyperbolic_arc_d(B, C, True) self._hyperbolic_arc_d(C, A, False) else: self._hyperbolic_arc_d(A, B, True) self._hyperbolic_arc_d(B, C, False) self._hyperbolic_arc_d(C, A, False) #self._hyperbolic_arc_d(A, B, True); #self._hyperbolic_arc_d(B, C); #self._hyperbolic_arc_d(C, A); #BezierPath.__init__(self, self.path, options) #super(HyperbolicTriangleDisc,self).__init__(options) self.A, self.B, self.C = (A, B, C)