notebook.community
Edit and run
In [1]: import numpy import toyplot.data data = toyplot.data.Table() data["a"] = numpy.array(["Foo-BAZ-46", "Bar-BAZ-46", "Foo-BAZ-23", "Bar-BAZ-23", "Foo-BLAH", "Bar-BLAH"]) data["b"] = numpy.array([0.381, 0.142, 0.473, 0.234, 0.165, 0.186]) data
import numpy import toyplot.data data = toyplot.data.Table() data["a"] = numpy.array(["Foo-BAZ-46", "Bar-BAZ-46", "Foo-BAZ-23", "Bar-BAZ-23", "Foo-BLAH", "Bar-BLAH"]) data["b"] = numpy.array([0.381, 0.142, 0.473, 0.234, 0.165, 0.186]) data
Out[1]: abFoo-BAZ-460.381Bar-BAZ-460.142Foo-BAZ-230.473Bar-BAZ-230.234Foo-BLAH0.165Bar-BLAH0.186
In [2]: colormap = toyplot.color.CategoricalMap() canvas = toyplot.Canvas(width=600, height=250) table = canvas.table(rows=6, columns=4, title="Quarterly Report") table.column(0).width = 50 table.column(1).data = data["a"] table.column(1).width = 90 table.column(3).data = data["b"] table.column(3).width = 55 table.column(3).format = toyplot.format.FloatFormatter(format="{:.2f}s") table.cell(0,0,rowspan=2).merge().data = "Red" table.cell(2,0,rowspan=2).merge().data = "Green" table.cell(4,0,rowspan=2).merge().data = "Blue" axes = table.cell(0, 2, rowspan=6).axes(show=True, yshow=False, padding=0, xlabel="Seconds") axes.x.spine.show = False axes.bars(data["b"][::-1], along="y", style={"stroke-width":8}, fill=numpy.array([0,1,0,1,0,1])[::-1], colormap=colormap);
colormap = toyplot.color.CategoricalMap() canvas = toyplot.Canvas(width=600, height=250) table = canvas.table(rows=6, columns=4, title="Quarterly Report") table.column(0).width = 50 table.column(1).data = data["a"] table.column(1).width = 90 table.column(3).data = data["b"] table.column(3).width = 55 table.column(3).format = toyplot.format.FloatFormatter(format="{:.2f}s") table.cell(0,0,rowspan=2).merge().data = "Red" table.cell(2,0,rowspan=2).merge().data = "Green" table.cell(4,0,rowspan=2).merge().data = "Blue" axes = table.cell(0, 2, rowspan=6).axes(show=True, yshow=False, padding=0, xlabel="Seconds") axes.x.spine.show = False axes.bars(data["b"][::-1], along="y", style={"stroke-width":8}, fill=numpy.array([0,1,0,1,0,1])[::-1], colormap=colormap);
Quarterly Report{"x": [{"domain": {"max": 0.5, "min": 0.0}, "range": {"max": 495.0, "min": 190.0}, "scale": "linear"}], "y": [{"domain": {"max": 5.5, "min": -0.5}, "range": {"max": 200.0, "min": 50.0}, "scale": "linear"}]}{"data": [[-0.5, 0.5, 1.5, 2.5, 3.5, 4.5], [0.5, 1.5, 2.5, 3.5, 4.5, 5.5], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.186, 0.165, 0.234, 0.473, 0.142, 0.381], [0.9882352941176471, 0.4, 0.9882352941176471, 0.4, 0.9882352941176471, 0.4], [0.5529411764705883, 0.7607843137254902, 0.5529411764705883, 0.7607843137254902, 0.5529411764705883, 0.7607843137254902], [0.3843137254901961, 0.6470588235294118, 0.3843137254901961, 0.6470588235294118, 0.3843137254901961, 0.6470588235294118], [1.0, 1.0, 1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0, 1.0, 1.0], [null, null, null, null, null, null]], "names": ["left", "right", "baseline", "magnitude0", "fill0:red", "fill0:green", "fill0:blue", "fill0:alpha", "opacity0", "title0"]}0.00.10.20.30.40.5SecondsFoo-BAZ-460.38sBar-BAZ-460.14sFoo-BAZ-230.47sBar-BAZ-230.23sFoo-BLAH0.17sBar-BLAH0.19sRedGreenBlueSave as .csv
In [3]: canvas = toyplot.Canvas(width=600, height=250) table = canvas.table(rows=6, columns=4, title="Quarterly Report") table.column(0).width = 50 table.column(1).data = data["a"] table.column(1).width = 90 table.column(3).width = 55 table.column(3).format = toyplot.format.FloatFormatter(format="{:.2f}s") table.cell(0,0,rowspan=2).merge().data = "Red" table.cell(2,0,rowspan=2).merge().data = "Green" table.cell(4,0,rowspan=2).merge().data = "Blue" for index, value in enumerate(data["b"]): axes = table.cell(index, 2).axes(padding=5, xmin=0, xmax=data["b"].max(), xlabel="Seconds", yshow=False) axes.bars([value], along="y", fill=colormap.color(index % 2)) axes.show = index == 5 axes.x.spine.show = False
canvas = toyplot.Canvas(width=600, height=250) table = canvas.table(rows=6, columns=4, title="Quarterly Report") table.column(0).width = 50 table.column(1).data = data["a"] table.column(1).width = 90 table.column(3).width = 55 table.column(3).format = toyplot.format.FloatFormatter(format="{:.2f}s") table.cell(0,0,rowspan=2).merge().data = "Red" table.cell(2,0,rowspan=2).merge().data = "Green" table.cell(4,0,rowspan=2).merge().data = "Blue" for index, value in enumerate(data["b"]): axes = table.cell(index, 2).axes(padding=5, xmin=0, xmax=data["b"].max(), xlabel="Seconds", yshow=False) axes.bars([value], along="y", fill=colormap.color(index % 2)) axes.show = index == 5 axes.x.spine.show = False
Quarterly Report{"x": [{"domain": {"max": 0.47299999999999998, "min": 0}, "range": {"max": 490.0, "min": 195.0}, "scale": "linear"}], "y": [{"domain": {"max": 0.5, "min": -0.5}, "range": {"max": 70.0, "min": 55.0}, "scale": "linear"}]}{"data": [[-0.5], [0.5], [0.0], [0.381], [0.4], [0.7607843137254902], [0.6470588235294118], [1.0], [1.0], [null]], "names": ["left", "right", "baseline", "magnitude0", "fill0:red", "fill0:green", "fill0:blue", "fill0:alpha", "opacity0", "title0"]}{"x": [{"domain": {"max": 0.47299999999999998, "min": 0}, "range": {"max": 490.0, "min": 195.0}, "scale": "linear"}], "y": [{"domain": {"max": 0.5, "min": -0.5}, "range": {"max": 95.0, "min": 80.0}, "scale": "linear"}]}{"data": [[-0.5], [0.5], [0.0], [0.142], [0.9882352941176471], [0.5529411764705883], [0.3843137254901961], [1.0], [1.0], [null]], "names": ["left", "right", "baseline", "magnitude0", "fill0:red", "fill0:green", "fill0:blue", "fill0:alpha", "opacity0", "title0"]}{"x": [{"domain": {"max": 0.47299999999999998, "min": 0}, "range": {"max": 490.0, "min": 195.0}, "scale": "linear"}], "y": [{"domain": {"max": 0.5, "min": -0.5}, "range": {"max": 120.0, "min": 105.0}, "scale": "linear"}]}{"data": [[-0.5], [0.5], [0.0], [0.473], [0.4], [0.7607843137254902], [0.6470588235294118], [1.0], [1.0], [null]], "names": ["left", "right", "baseline", "magnitude0", "fill0:red", "fill0:green", "fill0:blue", "fill0:alpha", "opacity0", "title0"]}{"x": [{"domain": {"max": 0.47299999999999998, "min": 0}, "range": {"max": 490.0, "min": 195.0}, "scale": "linear"}], "y": [{"domain": {"max": 0.5, "min": -0.5}, "range": {"max": 145.0, "min": 130.0}, "scale": "linear"}]}{"data": [[-0.5], [0.5], [0.0], [0.234], [0.9882352941176471], [0.5529411764705883], [0.3843137254901961], [1.0], [1.0], [null]], "names": ["left", "right", "baseline", "magnitude0", "fill0:red", "fill0:green", "fill0:blue", "fill0:alpha", "opacity0", "title0"]}{"x": [{"domain": {"max": 0.47299999999999998, "min": 0}, "range": {"max": 490.0, "min": 195.0}, "scale": "linear"}], "y": [{"domain": {"max": 0.5, "min": -0.5}, "range": {"max": 170.0, "min": 155.0}, "scale": "linear"}]}{"data": [[-0.5], [0.5], [0.0], [0.165], [0.4], [0.7607843137254902], [0.6470588235294118], [1.0], [1.0], [null]], "names": ["left", "right", "baseline", "magnitude0", "fill0:red", "fill0:green", "fill0:blue", "fill0:alpha", "opacity0", "title0"]}{"x": [{"domain": {"max": 0.5, "min": 0}, "range": {"max": 490.0, "min": 195.0}, "scale": "linear"}], "y": [{"domain": {"max": 0.5, "min": -0.5}, "range": {"max": 195.0, "min": 180.0}, "scale": "linear"}]}{"data": [[-0.5], [0.5], [0.0], [0.186], [0.9882352941176471], [0.5529411764705883], [0.3843137254901961], [1.0], [1.0], [null]], "names": ["left", "right", "baseline", "magnitude0", "fill0:red", "fill0:green", "fill0:blue", "fill0:alpha", "opacity0", "title0"]}0.00.10.20.30.40.5SecondsFoo-BAZ-46Bar-BAZ-46Foo-BAZ-23Bar-BAZ-23Foo-BLAHBar-BLAHRedGreenBlueSave as .csv
In [ ]: