def bar_chart(datalist, **options): """ A bar chart of (currently) one list of numerical data. Support for more data lists in progress. EXAMPLES: A bar_chart with blue bars:: sage: bar_chart([1,2,3,4]) Graphics object consisting of 1 graphics primitive A bar_chart with thinner bars:: sage: bar_chart([x^2 for x in range(1,20)], width=0.2) Graphics object consisting of 1 graphics primitive A bar_chart with negative values and red bars:: sage: bar_chart([-3,5,-6,11], rgbcolor=(1,0,0)) Graphics object consisting of 1 graphics primitive A bar chart with a legend (it's possible, not necessarily useful):: sage: bar_chart([-1,1,-1,1], legend_label='wave') Graphics object consisting of 1 graphics primitive Extra options will get passed on to show(), as long as they are valid:: sage: bar_chart([-2,8,-7,3], rgbcolor=(1,0,0), axes=False) Graphics object consisting of 1 graphics primitive sage: bar_chart([-2,8,-7,3], rgbcolor=(1,0,0)).show(axes=False) # These are equivalent """ dl = len(datalist) #if dl > 1: # print "WARNING, currently only 1 data set allowed" # datalist = datalist[0] if dl == 3: datalist = datalist + [0] #bardata = [] #cnt = 1 #for pnts in datalist: #ind = [i+cnt/dl for i in range(len(pnts))] #bardata.append([ind, pnts, xrange, yrange]) #cnt += 1 g = Graphics() g._set_extra_kwds(Graphics._extract_kwds_for_show(options)) #TODO: improve below for multiple data sets! #cnt = 1 #for ind, pnts, xrange, yrange in bardata: #options={'rgbcolor':hue(cnt/dl),'width':0.5/dl} # g._bar_chart(ind, pnts, xrange, yrange, options=options) # cnt += 1 #else: ind = list(range(len(datalist))) g.add_primitive(BarChart(ind, datalist, options=options)) if options['legend_label']: g.legend(True) return g
def bar_chart(datalist, **options): """ A bar chart of (currently) one list of numerical data. Support for more data lists in progress. EXAMPLES: A bar_chart with blue bars:: sage: bar_chart([1,2,3,4]) Graphics object consisting of 1 graphics primitive A bar_chart with thinner bars:: sage: bar_chart([x^2 for x in range(1,20)], width=0.2) Graphics object consisting of 1 graphics primitive A bar_chart with negative values and red bars:: sage: bar_chart([-3,5,-6,11], rgbcolor=(1,0,0)) Graphics object consisting of 1 graphics primitive A bar chart with a legend (it's possible, not necessarily useful):: sage: bar_chart([-1,1,-1,1], legend_label='wave') Graphics object consisting of 1 graphics primitive Extra options will get passed on to show(), as long as they are valid:: sage: bar_chart([-2,8,-7,3], rgbcolor=(1,0,0), axes=False) Graphics object consisting of 1 graphics primitive sage: bar_chart([-2,8,-7,3], rgbcolor=(1,0,0)).show(axes=False) # These are equivalent """ dl = len(datalist) #if dl > 1: # print "WARNING, currently only 1 data set allowed" # datalist = datalist[0] if dl == 3: datalist = datalist+[0] #bardata = [] #cnt = 1 #for pnts in datalist: #ind = [i+cnt/dl for i in range(len(pnts))] #bardata.append([ind, pnts, xrange, yrange]) #cnt += 1 g = Graphics() g._set_extra_kwds(Graphics._extract_kwds_for_show(options)) #TODO: improve below for multiple data sets! #cnt = 1 #for ind, pnts, xrange, yrange in bardata: #options={'rgbcolor':hue(cnt/dl),'width':0.5/dl} # g._bar_chart(ind, pnts, xrange, yrange, options=options) # cnt += 1 #else: ind = list(range(len(datalist))) g.add_primitive(BarChart(ind, datalist, options=options)) if options['legend_label']: g.legend(True) return g
def arc(center, r1, r2=None, angle=0.0, sector=(0.0, 2 * pi), **options): r""" An arc (that is a portion of a circle or an ellipse) Type ``arc.options`` to see all options. INPUT: - ``center`` - 2-tuple of real numbers - position of the center. - ``r1``, ``r2`` - positive real numbers - radii of the ellipse. If only ``r1`` is set, then the two radii are supposed to be equal and this function returns an arc of circle. - ``angle`` - real number - angle between the horizontal and the axis that corresponds to ``r1``. - ``sector`` - 2-tuple (default: (0,2*pi))- angles sector in which the arc will be drawn. OPTIONS: - ``alpha`` - float (default: 1) - transparency - ``thickness`` - float (default: 1) - thickness of the arc - ``color``, ``rgbcolor`` - string or 2-tuple (default: 'blue') - the color of the arc - ``linestyle`` - string (default: ``'solid'``) - The style of the line, which is one of ``'dashed'``, ``'dotted'``, ``'solid'``, ``'dashdot'``, or ``'--'``, ``':'``, ``'-'``, ``'-.'``, respectively. EXAMPLES: Plot an arc of circle centered at (0,0) with radius 1 in the sector `(\pi/4,3*\pi/4)`:: sage: arc((0,0), 1, sector=(pi/4,3*pi/4)) Graphics object consisting of 1 graphics primitive Plot an arc of an ellipse between the angles 0 and `\pi/2`:: sage: arc((2,3), 2, 1, sector=(0,pi/2)) Graphics object consisting of 1 graphics primitive Plot an arc of a rotated ellipse between the angles 0 and `\pi/2`:: sage: arc((2,3), 2, 1, angle=pi/5, sector=(0,pi/2)) Graphics object consisting of 1 graphics primitive Plot an arc of an ellipse in red with a dashed linestyle:: sage: arc((0,0), 2, 1, 0, (0,pi/2), linestyle="dashed", color="red") Graphics object consisting of 1 graphics primitive sage: arc((0,0), 2, 1, 0, (0,pi/2), linestyle="--", color="red") Graphics object consisting of 1 graphics primitive The default aspect ratio for arcs is 1.0:: sage: arc((0,0), 1, sector=(pi/4,3*pi/4)).aspect_ratio() 1.0 It is not possible to draw arcs in 3D:: sage: A = arc((0,0,0), 1) Traceback (most recent call last): ... NotImplementedError """ from sage.plot.all import Graphics # Reset aspect_ratio to 'automatic' in case scale is 'semilog[xy]'. # Otherwise matplotlib complains. scale = options.get('scale', None) if isinstance(scale, (list, tuple)): scale = scale[0] if scale == 'semilogy' or scale == 'semilogx': options['aspect_ratio'] = 'automatic' if len(center) == 2: if r2 is None: r2 = r1 g = Graphics() g._set_extra_kwds(Graphics._extract_kwds_for_show(options)) if len(sector) != 2: raise ValueError("the sector must consist of two angles") g.add_primitive( Arc(center[0], center[1], r1, r2, angle, sector[0], sector[1], options)) return g elif len(center) == 3: raise NotImplementedError
def arc(center, r1, r2=None, angle=0.0, sector=(0.0, 2 * pi), **options): r""" An arc (that is a portion of a circle or an ellipse) Type ``arc.options`` to see all options. INPUT: - ``center`` - 2-tuple of real numbers - position of the center. - ``r1``, ``r2`` - positive real numbers - radii of the ellipse. If only ``r1`` is set, then the two radii are supposed to be equal and this function returns an arc of of circle. - ``angle`` - real number - angle between the horizontal and the axis that corresponds to ``r1``. - ``sector`` - 2-tuple (default: (0,2*pi))- angles sector in which the arc will be drawn. OPTIONS: - ``alpha`` - float (default: 1) - transparency - ``thickness`` - float (default: 1) - thickness of the arc - ``color``, ``rgbcolor`` - string or 2-tuple (default: 'blue') - the color of the arc - ``linestyle`` - string (default: ``'solid'``) - The style of the line, which is one of ``'dashed'``, ``'dotted'``, ``'solid'``, ``'dashdot'``, or ``'--'``, ``':'``, ``'-'``, ``'-.'``, respectively. EXAMPLES: Plot an arc of circle centered at (0,0) with radius 1 in the sector `(\pi/4,3*\pi/4)`:: sage: arc((0,0), 1, sector=(pi/4,3*pi/4)) Graphics object consisting of 1 graphics primitive Plot an arc of an ellipse between the angles 0 and `\pi/2`:: sage: arc((2,3), 2, 1, sector=(0,pi/2)) Graphics object consisting of 1 graphics primitive Plot an arc of a rotated ellipse between the angles 0 and `\pi/2`:: sage: arc((2,3), 2, 1, angle=pi/5, sector=(0,pi/2)) Graphics object consisting of 1 graphics primitive Plot an arc of an ellipse in red with a dashed linestyle:: sage: arc((0,0), 2, 1, 0, (0,pi/2), linestyle="dashed", color="red") Graphics object consisting of 1 graphics primitive sage: arc((0,0), 2, 1, 0, (0,pi/2), linestyle="--", color="red") Graphics object consisting of 1 graphics primitive The default aspect ratio for arcs is 1.0:: sage: arc((0,0), 1, sector=(pi/4,3*pi/4)).aspect_ratio() 1.0 It is not possible to draw arcs in 3D:: sage: A = arc((0,0,0), 1) Traceback (most recent call last): ... NotImplementedError """ from sage.plot.all import Graphics # Reset aspect_ratio to 'automatic' in case scale is 'semilog[xy]'. # Otherwise matplotlib complains. scale = options.get('scale', None) if isinstance(scale, (list, tuple)): scale = scale[0] if scale == 'semilogy' or scale == 'semilogx': options['aspect_ratio'] = 'automatic' if len(center) == 2: if r2 is None: r2 = r1 g = Graphics() g._set_extra_kwds(Graphics._extract_kwds_for_show(options)) if len(sector) != 2: raise ValueError("the sector must consist of two angles") g.add_primitive(Arc( center[0], center[1], r1, r2, angle, sector[0], sector[1], options)) return g elif len(center) == 3: raise NotImplementedError