Bar charts#
- class sage.plot.bar_chart.BarChart(ind, datalist, options)[source]#
Bases:
GraphicPrimitive
Graphics primitive that represents a bar chart.
EXAMPLES:
sage: from sage.plot.bar_chart import BarChart sage: g = BarChart(list(range(4)), [1,3,2,0], {}); g BarChart defined by a 4 datalist sage: type(g) <class 'sage.plot.bar_chart.BarChart'>
>>> from sage.all import * >>> from sage.plot.bar_chart import BarChart >>> g = BarChart(list(range(Integer(4))), [Integer(1),Integer(3),Integer(2),Integer(0)], {}); g BarChart defined by a 4 datalist >>> type(g) <class 'sage.plot.bar_chart.BarChart'>
- get_minmax_data()[source]#
Returns a dictionary with the bounding box data.
EXAMPLES:
sage: b = bar_chart([-2.3,5,-6,12]) sage: d = b.get_minmax_data() sage: d['xmin'] 0 sage: d['xmax'] 4
>>> from sage.all import * >>> b = bar_chart([-RealNumber('2.3'),Integer(5),-Integer(6),Integer(12)]) >>> d = b.get_minmax_data() >>> d['xmin'] 0 >>> d['xmax'] 4
- sage.plot.bar_chart.bar_chart(datalist, width=0.5, rgbcolor=(0, 0, 1), legend_label=None, aspect_ratio='automatic', **options)[source]#
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
>>> from sage.all import * >>> bar_chart([Integer(1),Integer(2),Integer(3),Integer(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
>>> from sage.all import * >>> bar_chart([x**Integer(2) for x in range(Integer(1),Integer(20))], width=RealNumber('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
>>> from sage.all import * >>> bar_chart([-Integer(3),Integer(5),-Integer(6),Integer(11)], rgbcolor=(Integer(1),Integer(0),Integer(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
>>> from sage.all import * >>> bar_chart([-Integer(1),Integer(1),-Integer(1),Integer(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
>>> from sage.all import * >>> bar_chart([-Integer(2),Integer(8),-Integer(7),Integer(3)], rgbcolor=(Integer(1),Integer(0),Integer(0)), axes=False) Graphics object consisting of 1 graphics primitive >>> bar_chart([-Integer(2),Integer(8),-Integer(7),Integer(3)], rgbcolor=(Integer(1),Integer(0),Integer(0))).show(axes=False) # These are equivalent