def plot = new Plot(title: "We Will Control the Title", xLabel: "Horizontal", yLabel: "Vertical")
def ys = [0, 1, 6, 5, 2, 8]
def ys2 = [0, 2, 7, 6, 3, 8]
plot << new Line(y: ys, width: 10, color: Color.red)
plot << new Line(y: ys, width: 3, color: Color.yellow)
plot << new Line(y: ys, width: 4, color: new Color(33, 87, 141), style: StrokeType.DASH, interpolation: 0)
plot << new Line(y: ys2, width: 2, color: new Color(212, 57, 59), style: StrokeType.DOT)
plot << new Line(y: [5, 0], x: [0, 5], style: StrokeType.LONGDASH)
plot << new Line(y: [4, 0], x: [0, 5], style: StrokeType.DASHDOT)
def ch = new Crosshair(color: new Color(255, 128, 5), width: 2, style: StrokeType.DOT)
pp = new Plot(crosshair: ch, omitCheckboxes: true,
legendLayout: LegendLayout.HORIZONTAL, legendPosition: LegendPosition.TOP)
def x = [1, 4, 6, 8, 10]
def y = [3, 6, 4, 5, 9]
pp << new Line(displayName: "Line", x: x, y: y, width: 3)
pp << new Bars(displayName: "Bar", x: (1..10), y: [2, 2, 4, 4, 2, 2, 0, 2, 2, 4], width: 0.5)
pp << new Points(x: x, y: y, size: 10, toolTip: {xs, ys -> "x = " + xs + ", y = " + ys })
import com.twosigma.beakerx.fileloader.CSV
rates = new CSV().read("../../../doc/resources/data/interest-rates.csv")
def size = rates.size()
(0 ..< size).each{row = rates[it]; row.spread = row.y10 - row.m3}
OutputCell.HIDDEN
new SimpleTimePlot(rates, ["y1", "y10"], // column names
timeColumn : "time", // time is default value for a timeColumn
yLabel: "Price",
displayNames: ["1 Year", "10 Year"],
colors : [[216, 154, 54], '#aabbcc'],
displayLines: false, // no lines (true by default)
displayPoints: true) // show points (false by default))
def cal = Calendar.getInstance();
cal.add(Calendar.HOUR, -1)
def today = new Date();
def millis = today.time;
def hour = 1000 * 60 * 60;
def plot = new TimePlot(
timeZone: new SimpleTimeZone(10800000, "America/New_York")
);
//list of milliseconds
plot << new Points(x:(0..10).collect{millis + hour * it}, y:(0..10), size: 10, displayName: "milliseconds");
//list of java.util.Date objects
plot << new Points(x:(0..10).collect{cal.add(Calendar.HOUR, 1); cal.getTime()}, y:(0..10), size: 4, displayName: "date objects");
// Generate some random data
Random random = new Random();
dataH1 = [];
dataH2 = [];
(1..10000).each {
dataH1 << random.nextGaussian();
dataH2 << 2*random.nextGaussian() + 1.0;
}
OutputCell.HIDDEN
new Histogram(initWidth:444, initHeight:400,
title:"Wide Histogram with Manual Parameters",
xLabel:"Size",
yLabel:"Count",
rangeMin: -8,
rangeMax: 8,
data: dataH1 + [7]*200,
binCount: 99,
color: new Color(0, 154, 166));
dataHM = [[533.08714795974, 484.92105712087596, 451.63070008303896, 894.4451947886148, 335.44965728686225, 640.9424094527392, 776.2709495045433, 621.8819257981404, 793.2905673902735, 328.97078791524234, 139.26962328268513, 800.9314566259062, 629.0795214099808, 418.90954534196544, 513.8036215424278, 742.9834968485734, 542.9393528649774, 671.4256827205828, 507.1129322933082, 258.8238039352692, 581.0354187924672, 190.1830169180297, 480.461111816312, 621.621218137835, 650.6023460248642, 635.7577683708486, 605.5201537254429, 364.55368485516846, 554.807212844458, 526.1823154945637], [224.1432052432479, 343.26660237811336, 228.29828973027486, 550.3809606942758, 340.16890889700994, 214.05332637480836, 461.3159325548031, 471.2546571575069, 503.071081294441, 757.4281483575993, 493.82140462579406, 579.4302306011925, 459.76905409338497, 580.1282535427403, 378.8722877921564, 442.8806517248869, 573.9346962907078, 449.0587543606964, 383.50503527041144, 378.90761994599256, 755.1883447435789, 581.6815170672886, 426.56807864689773, 602.6727518023347, 555.6481983927658, 571.1201152862207, 372.24744704437876, 424.73180136220844, 739.9173564499195, 462.3257604373609], [561.8684320610753, 604.2859791599086, 518.3421287392559, 524.6887104615442, 364.41920277904774, 433.37737233751386, 565.0508404421712, 533.6030951907703, 306.68809206630397, 738.7229466356732, 766.9678519097575, 699.8457506281374, 437.0340850742263, 802.4400914789037, 417.38754410115075, 907.5825538527938, 521.4281410545287, 318.6109350534576, 435.8275858900637, 463.82924688853524, 533.4069709666686, 404.50516534982546, 332.6966202103611, 560.0346672408426, 436.9691072984075, 631.3453929454839, 585.1581992195356, 522.3209865675237, 497.57041075817443, 525.8867246757814], [363.4020792898871, 457.31257834906256, 333.21325206873564, 508.0466632081777, 457.1905718373847, 611.2168422907173, 515.2088862309242, 674.5569500790505, 748.0512665828364, 889.7281605626981, 363.6454276219251, 647.0396659692233, 574.150119779024, 721.1853645071792, 309.5388283799724, 450.51745569875845, 339.1271937333267, 630.6976744426033, 630.1571298446103, 615.0700456998867, 780.7843408745639, 205.13803869051543, 784.5916902014255, 498.10545868387925, 553.936345186856, 207.59216580556847, 488.12270849418735, 422.6667046886397, 292.1061953879919, 565.1595338825396], [528.5186504364794, 642.5542319036714, 563.8776991112292, 537.0271437681837, 430.4056097950834, 384.50193545472877, 693.3404035076994, 573.0278734604005, 261.2443087970927, 563.412635691231, 258.13860041989085, 550.150017102056, 477.70582135030617, 509.4311099345934, 661.3308013433317, 523.1175760654914, 370.29659041946326, 557.8704186019502, 353.66591951113645, 510.5389425077261, 469.11212447314324, 626.2863927887214, 318.5642686423241, 141.13900677851177, 486.00711121264453, 542.0075639686526, 448.7161764573215, 376.65492084577164, 166.56246586635706, 718.6147921685923], [435.403218786657, 470.74259129379413, 615.3542648093958, 483.61792559031693, 607.9455289424717, 454.9949861614464, 869.45041758392, 750.3595195751914, 754.7958625343501, 508.38715645396553, 368.2779213892305, 662.23752125613, 350.46366230046397, 619.8010888063362, 497.9560438683688, 420.64163974607766, 487.16698403905633, 273.3352931767504, 354.02637708217384, 457.9408818614016, 496.2986534025747, 364.84710143814976, 458.29907844925157, 634.073520178434, 558.7161089429649, 603.6634230782621, 514.1019407724017, 539.6741842214251, 585.0639516732675, 488.3003071211236], [334.0264519516021, 459.5702037859653, 543.8547654459309, 471.6623772418301, 500.98627686914386, 740.3857774449933, 487.4853744264201, 664.5373560191691, 573.764159193263, 471.32565842016527, 448.8845519093864, 729.3173859836543, 453.34766656988694, 428.4975196541853, 575.1404740691066, 190.18782164376034, 243.90403003048107, 430.03959300145215, 429.08666492876233, 508.89662188951297, 669.6400651031191, 516.2894766192492, 441.39320293407405, 653.1948574772491, 529.6831617222962, 176.0833629734244, 568.7136007686755, 461.66494617366294, 443.39303344518356, 840.642834252332], [347.676690455591, 475.0701395711058, 383.94468812449156, 456.7512619303556, 547.1719187673109, 224.69458657065758, 458.98685335259506, 599.8561007491281, 231.02565460233575, 610.5318803183029, 763.3423474509603, 548.8104762105211, 445.95788564834953, 844.6566709331175, 591.2236009653337, 586.0438760821825, 399.6820689195621, 395.17360423878256, 535.9853351258233, 332.27242110850426, 801.7584039310705, 190.6337233666032, 805.700536966829, 799.6824375238089, 346.29917202656327, 611.7423892505719, 705.8824305058062, 535.9691379719488, 488.1708623023391, 604.3772264289142], [687.7108994865216, 483.44749361779685, 661.8182197739575, 591.5452701990528, 151.60961549943875, 524.1475889465452, 745.1142999852398, 665.6103992924466, 701.3015233859578, 648.9854638583182, 403.08097902196505, 384.97216329583586, 442.52161997463816, 590.5026536093199, 219.04366558018955, 899.2103705796073, 562.4908789323547, 666.088957218587, 496.97593850278065, 777.9572405840922, 531.7316118485633, 500.7782009017233, 646.4095967934252, 633.5713368259554, 608.1857007168994, 585.4020395597571, 490.06193749044934, 463.884131549627, 632.7981360348942, 634.8055942938928], [482.5550451528366, 691.7011356960619, 496.2851035642388, 529.4040886765091, 444.3593296445004, 198.06208336708823, 365.6472909266031, 391.3885069938369, 859.494451604626, 275.19483951927816, 568.4478784631463, 203.74971298680123, 676.2053582803082, 527.9859302404323, 714.4565600799949, 288.9012675397431, 629.6056652113498, 326.2525932990075, 519.5740740263301, 696.8119752318905, 347.1796230415255, 388.6576994098651, 357.54758351840974, 873.5528483422207, 507.0189947052724, 508.1981784529926, 536.9527958233257, 871.2838601964829, 361.93416709279154, 496.5981745168124]]
new HeatMap(title: "Heatmap Second Example",
xLabel:"X Label",
yLabel:"Y Label",
data: dataHM,
legendPosition: LegendPosition.TOP)
// generate a random walk
steps = 10000
random = new Random()
def walk(ssize) {
def cur = 0.0
def x = []
def y = []
for (i in 0..steps) {
y[i] = cur
x[i] = i
cur += random.nextGaussian() * ssize
}
return [x:x, y:y]
}
// now x is time for the x-axis, and y is the random variable
beer = walk(10)
whiskey = walk(100)
OutputCell.HIDDEN
p = new TimePlot(title: "Drunken Sailor Walks", showLegend: true, lodThreshold: 2000)
p << new Line(x:beer.x, y:beer.y, displayName:"Beer Walk")
p << new Line(x:whiskey.x, y:whiskey.y, displayName:"Whiskey Walk")
node = new TreeMapNode("0");
def node00 = new TreeMapNode("00", 2, new DefaultValue(2));
def node01 = new TreeMapNode("01");
node01.add(new TreeMapNode("011", 1, new DefaultValue(1)))
node01.add(new TreeMapNode("012", 2, new DefaultValue(1)))
node01.add(new TreeMapNode("013", 3, new DefaultValue(1)))
def node02 = new TreeMapNode("02");
node02.add(new TreeMapNode("020", 2, new DefaultValue(2)))
node02.add(new TreeMapNode("021", 1, new DefaultValue(1)))
node02.add(new TreeMapNode("022", 1, new DefaultValue(1)))
node02.add(new TreeMapNode("023", 1, new DefaultValue(1)))
node02.add(new TreeMapNode("024", 2, new DefaultValue(2)))
def node03 = new TreeMapNode("03");
node03.add(new TreeMapNode("030", 1, new DefaultValue(2)))
node03.add(new TreeMapNode("031", 2, new DefaultValue(2)))
node03.add(new TreeMapNode("032", 3, new DefaultValue(2)))
node03.add(new TreeMapNode("033", 4, new DefaultValue(2)))
def node04 = new TreeMapNode("04", 6, new DefaultValue(5))
node.add(node01)
node.add(node02)
node.add(node03)
node.add(node04)
OutputCell.HIDDEN
def x = new TreeMap(
root: node,
showLegend: true,
title: "Simple TreeChart"
);
x
def cplot = new CategoryPlot(title: "Hello CategoryPlot!",
xLabel: "Categories",
yLabel: "Values")
cplot << new CategoryBars(value:[[1, 2, 3], [1, 3, 5]])
import com.twosigma.beakerx.table.*
import com.twosigma.beakerx.table.format.TableDisplayStringFormat
display = new TableDisplay(new CSV().read("../../../doc/resources/data/interest-rates.csv"))
//show all time columns in days
display.setStringFormatForTimes(TimeUnit.DAYS)
//min 4, max 6 decimal places for all doubles
display.setStringFormatForType(ColumnType.Double, TableDisplayStringFormat.getDecimalFormat(4,6))
//setting for a column takes precidence over the type
display.setStringFormatForColumn("m3", TableDisplayStringFormat.getDecimalFormat(0, 0))
//set the alignment
display.setAlignmentProviderForType(ColumnType.Double, TableDisplayAlignmentProvider.RIGHT_ALIGNMENT)
display.setAlignmentProviderForColumn('m3', TableDisplayAlignmentProvider.CENTER_ALIGNMENT)
//using a closure
display.setStringFormatForColumn("y3") { value, row, col, tableDisplay ->
if(value < 8) {
":("
} else {
":)"
}
}
display
import com.twosigma.beakerx.table.highlight.*
def table = new TableDisplay([[1,2,3],
[3,4,5],
[6,2,8],
[6,2,8],
[6,2,8],
[6,4,8],
[6,2,8],
[6,2,8],
[6,5,8]],
['a', 'b', 'c'],
['double', 'double', 'double'])
table.addCellHighlighter(TableDisplayCellHighlighter.getUniqueEntriesHighlighter("b", TableDisplayCellHighlighter.FULL_ROW))
table