Skip to content

Instantly share code, notes, and snippets.

@scottdraves
Created January 11, 2018 21:46
Show Gist options
  • Select an option

  • Save scottdraves/15511b5555c0ee39bdbf13091ef615aa to your computer and use it in GitHub Desktop.

Select an option

Save scottdraves/15511b5555c0ee39bdbf13091ef615aa to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {},
"cell_type": "markdown",
"source": "# Creating a Plot"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "This section goes over the steps required to create a plot, configure it, and add data and graphics to it."
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Title and Axis Labels"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "new Plot(title: \"We Will Control the Title\", xLabel: \"Horizontal\", yLabel: \"Vertical\")",
"execution_count": 2,
"outputs": [
{
"output_type": "display_data",
"data": {
"method": "display_data",
"application/vnd.jupyter.widget-view+json": {
"version_minor": 0,
"model_id": "7c37e610-f9e1-4516-9bbe-080719c5860c",
"version_major": 2
}
},
"metadata": {}
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Lines"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "There are multiple ways\nto specify the points of the line using Groovy. All the following lines achieve\nthe same result."
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "// just provide lists of x's and y's\nnew Plot().add(new Line(x: [0, 1, 2, 3, 4, 5], y: [0, 1, 6, 5, 2, 8]))\n\n// Groovy range works\nnew Plot().add(new Line(x: (0..5), y: [0, 1, 6, 5, 2, 8]))\n\n// use '<<' left-shift to save some key strokes\nnew Plot() << new Line(x: (0..5), y: [0, 1, 6, 5, 2, 8])\n\n// the constructor of class Line is overloaded to take 1 or 2 lists\n// if an Line was returned, and empty plot is automatically generated\nnew Line((0..5), [0, 1, 6, 5, 2, 8])\n \n// if x is not provided, a default list of x values (0..5) will be used\nnew Line([0, 1, 6, 5, 2, 8])",
"execution_count": 1,
"outputs": [
{
"output_type": "display_data",
"data": {
"method": "display_data",
"application/vnd.jupyter.widget-view+json": {
"version_minor": 0,
"model_id": "dd5f5356-c4fb-49f0-a4f2-b11c9cbf034c",
"version_major": 2
}
},
"metadata": {}
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "You may change the\nrendering properties of the lines, by specifying the corresponding parameters. E.g.\nwidth, color, style, interpolation, etc."
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "def plot = new Plot(title: \"Setting line properties\")\ndef ys = [0, 1, 6, 5, 2, 8]\ndef ys2 = [0, 2, 7, 6, 3, 8]\nplot << new Line(y: ys, width: 10, color: Color.red)\nplot << new Line(y: ys, width: 3, color: Color.yellow)\nplot << new Line(y: ys, width: 4, color: new Color(33, 87, 141), style: StrokeType.DASH, interpolation: 0)\nplot << new Line(y: ys2, width: 2, color: new Color(212, 57, 59), style: StrokeType.DOT)\nplot << new Line(y: [5, 0], x: [0, 5], style: StrokeType.LONGDASH)\nplot << new Line(y: [4, 0], x: [0, 5], style: StrokeType.DASHDOT)",
"execution_count": null,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Stems"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "Stems are vertical line\nsegments. All the rendering properties for lines apply to stems."
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "def plot = new Plot();\ndef y1 = [1.5, 1, 6, 5, 2, 8]\ndef cs = [Color.black, Color.red, Color.gray, Color.green, Color.blue, Color.pink]\ndef ss = [StrokeType.SOLID, StrokeType.SOLID, StrokeType.DASH, StrokeType.DOT, StrokeType.DASHDOT, StrokeType.LONGDASH]\nplot << new Stems(y: y1, color: cs, style: ss, width: 5)",
"execution_count": null,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "Draw points at the top /\nbottom of stems to make stem bases"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "def plot = new Plot(title: \"Setting the base of Stems\")\ndef ys = [3, 5, 2, 3, 7]\ndef y2s = [2.5, -1.0, 3.5, 2.0, 3.0]\nplot << new Stems(y: ys, width: 2, base: y2s)\nplot << new Points(y: ys)",
"execution_count": null,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Bars"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "You can set the width and color of the bars. You can set the color property for each single bar element using a list\nBar colors are fill colors, To change the outline color, use *outlineColor*.\nBar width is in terms of the data domain.\n\nFor Bar Charts, see the other tutorial on Category Plots."
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "def plot = new Plot(title: \"Bars\")\ndef cs = [new Color(255, 0, 0, 128)] * 5 // transparent bars\ncs[3] = Color.red // set color of a single bar, solid colored bar\nplot << new Bars(x: (1..5), y: [3, 5, 2, 3, 7], color: cs, outlineColor: Color.black, width: 0.3)",
"execution_count": null,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Points"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "You can change the size and shape of points. Points also support *outlineColor*."
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "def plot = new Plot(title: \"Changing Point Size, Color, Shape\")\ndef y1 = [6, 7, 12, 11, 8, 14]\ndef y2 = y1.collect { it - 2 }\ndef y3 = y2.collect { it - 2 }\ndef y4 = y3.collect { it - 2 }\nplot << new Points(y: y1)\nplot << new Points(y: y2, shape: ShapeType.CIRCLE)\nplot << new Points(y: y3, size: 8.0, shape: ShapeType.DIAMOND)\nplot << new Points(y: y4, size: 12.0, color: Color.orange, outlineColor: Color.red)",
"execution_count": null,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "You can also set point properties using lists."
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "def plot = new Plot(title: \"Changing point properties with list\")\ndef cs = [Color.black, Color.red, Color.orange, Color.green, Color.blue, Color.pink]\ndef ss = [6.0, 9.0, 12.0, 15.0, 18.0, 21.0]\ndef fs = [false, false, false, true, false, false]\nplot << [new Points(y: [5] * 6, size: 12.0, color: cs),\n new Points(y: [4] * 6, size: 12.0, color: Color.gray, outlineColor: cs),\n new Points(y: [3] * 6, size: ss, color: Color.red),\n new Points(y: [2] * 6, size: 12.0, color: Color.black, fill: fs, outlineColor: Color.black)]",
"execution_count": null,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Areas"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "def plot = new Plot()\ndef y = [3, 5, 2, 3]\ndef x0 = [0, 1, 2, 3]\ndef x1 = [3, 4, 5, 8]\nplot << new Area(x: x0, y: y)\nplot << new Area(x: x1, y: y, color: new Color(128, 128, 128, 50), interpolation: 0)",
"execution_count": null,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "You can also set bases for the areas."
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "def p = new Plot()\np << new Line(y: [3, 6, 12, 24], displayName: \"Median\")\np << new Area(y: [4, 8, 16, 32], base: [2, 4, 8, 16],\n color: new Color(255, 0, 0, 50), displayName: \"Q1 to Q3\")",
"execution_count": null,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Stacking"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "You can combine plot items that have a base property (Bars, Stems, Area)."
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "def y1 = [1,5,3,2,3]\ndef y2 = [7,2,4,1,3]\ndef p = new Plot(title: 'Plot with XYStacker', initHeight: 200)\ndef a1 = new Area(y: y1, displayName: 'y1')\ndef a2 = new Area(y: y2, displayName: 'y2')\np << XYStacker.stack([a1, a2])",
"execution_count": null,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Constant Lines"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "def p = new Plot ()\np << new Line(y: [-1, 1])\np << new ConstantLine(x: 0.65, style: StrokeType.DOT, color: Color.blue)\np << new ConstantLine(y: 0.1, style: StrokeType.DASHDOT, color: Color.blue)\np << new ConstantLine(x: 0.3, y: 0.4, color: Color.gray, width: 5, showLabel: true)",
"execution_count": null,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Constant Bands"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "new Plot() << new Line(y: [-3, 1, 3, 4, 5]) << new ConstantBand(x: [1, 2], y: [1, 3])",
"execution_count": null,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "You can change bands colors and use Infinity for values"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "def p = new Plot() \np << new Line(x: [-3, 1, 2, 4, 5], y: [4, 2, 6, 1, 5])\np << new ConstantBand(x: [Double.NEGATIVE_INFINITY, 1], color: new Color(128, 128, 128, 50))\np << new ConstantBand(x: [1, 2])\np << new ConstantBand(x: [4, Double.POSITIVE_INFINITY])",
"execution_count": null,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Text"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "def plot = new Plot()\ndef xs = (1..10)\ndef ys = [8.6, 6.1, 7.4, 2.5, 0.4, 0.0, 0.5, 1.7, 8.4, 1]\ndef label = { i ->\n if (ys[i] > ys[i+1] && ys[i] > ys[i-1]) return \"max\"\n if (ys[i] < ys[i+1] && ys[i] < ys[i-1]) return \"min\"\n if (ys[i] > ys[i-1]) return \"rising\"\n if (ys[i] < ys[i-1]) return \"falling\"\n return \"\"\n}\nfor (i = 0; i < xs.size(); i++) {\n if (i > 0 && i < xs.size()-1)\n plot << new Text(x: xs[i], y: ys[i], text: label(i), pointerAngle: -i/3.0)\n}\nplot << new Line(x: xs, y: ys)\nplot << new Points(x: xs, y: ys)",
"execution_count": null,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Legend"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## ToolTip ##\n\nThe Beaker Plot includes tool tips. Hover the changing points of the line or the bars to see them in the\nplot below.\n\nYou can interact with the tooltips.\n* Stick a tooltip: Click while a tooltip is visible, and it will remain until you close it by clicking the X.\n* Click and drag a tooltip to increase its visibility.\n* When you zoom and pan, the tooltip will try to keep its place within the plot when you later navigate.\n"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Legend box ##\nThe Beaker Plots include a legend box by default. You may drag the legend box around just as you drag the tool tips.\n\nThe legend box includes\nthe control panel features that allow you to show / hide data groups by\ntoggling the checkboxes. You may turn off this feature by using an “omitCheckboxes” property (in this case there would be no checkbox to show / hide data).\n\nUse “displayName” to show the data’s legend. The legend will automatically appear when a “displayName”\nproperty presents. However, you my turn the legend off explicitly by setting “showLegend”.\n\nIf you do not specify\nthe “displayName” property, or the “displayName” is an empty string, the data\nwill not appear in the legend box.\n\nBy default the legend is placed in the top-right corner. To change its position you can specify a “legendPosition” property. You can use predefined values (TOP, TOP_LEFT, etc..) or provide an array of coordinates (x, y).\n\nAlso you can change legend’s layout to horizontal by setting a “legendLayout” property."
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Cursor hint ##\n\nThe cursor hint allows\nyou to quickly identify the x / y values of the mouse location.Use “crosshair” property\nto enable the cursor hint. \n\nThe Crosshair object has properties similar to a\nLine, including color, width and style"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## TRY IT NOW! ##\n\nNow it would be a good\ntime for you to try the above interactions in the following demo plot. Make sure you try out\nthe following things:\n\n* Click a line point / bar to stick its tool tip.\n* Drag a tool tip around.\n* Show / hide the line or the bar group using the legend box\n* Change the legend box layout to horizontal and position to top-left"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "def ch = new Crosshair(color: new Color(255, 128, 5), width: 2, style: StrokeType.DOT)\npp = new Plot(crosshair: ch, omitCheckboxes: true,\n legendLayout: LegendLayout.HORIZONTAL, legendPosition: LegendPosition.TOP)\ndef x = [1, 4, 6, 8, 10]\ndef y = [3, 6, 4, 5, 9]\npp << new Line(displayName: \"Line\", x: x, y: y, width: 3)\npp << new Bars(displayName: \"Bar\", x: (1..10), y: [2, 2, 4, 4, 2, 2, 0, 2, 2, 4], width: 0.5)\npp << new Points(x: x, y: y, size: 10, toolTip: {xs, ys -> \"x = \" + xs + \", y = \" + ys })",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "pp.setLegendPosition(LegendPosition.RIGHT);\nOutputCell.HIDDEN",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "import com.twosigma.beakerx.fileloader.CsvPlotReader\nrates = new CsvPlotReader().read(\"../resources/data/interest-rates.csv\")\ndef size = rates.size()\n(0 ..< size).each{row = rates[it]; row.spread = row.y10 - row.m3}",
"execution_count": null,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Simple Time Plot"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "Using SimpleTimePlot you can create a time plot based on the complex table data.\nTo do this just specify table and table column names for plot, like in the\nexample at the top of this notebook.\n\nData for time axis is taken from 'time' column. To change this behavior use 'timeColumn' parameter.\n\nBy default lines are used to draw the plot, but you can also add points using the parameter 'displayPoints'.\nThe 'displayNames' property give sthe names of the lines, as displayedin the legend.\nTo specify custom colors use the 'colors' parameter, and give it a list with colors in\na variety of formats."
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "new SimpleTimePlot(rates, [\"y1\", \"y10\"], // column names\n timeColumn : \"time\", // time is default value for a timeColumn\n yLabel: \"Price\", \n displayNames: [\"1 Year\", \"10 Year\"],\n colors : [[216, 154, 54], '#aabbcc'],\n displayLines: false, // no lines (true by default)\n displayPoints: true) // show points (false by default))",
"execution_count": null,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Second Y Axis"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "The plot can have two y-axes. Just add a `YAxis` to the plot object, and specify its label.\nThen for data that should be scaled according to this second axis,\nspecify the property `yAxis` with a value that coincides with the label given.\nYou can use `upperMargin` and `lowerMargin` to restrict the range of the data leaving more white, perhaps for the data on the other axis."
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "def p = new TimePlot(xLabel: \"Time\", yLabel: \"Interest Rates\")\np << new YAxis(label: \"Spread\", upperMargin: 4)\np << new Area(x: rates.time, y: rates.spread, displayName: \"Spread\",\n yAxis: \"Spread\", color: new Color(180, 50, 50, 128))\np << new Line(x: rates.time, y: rates.m3, displayName: \"3 Month\")\np << new Line(x: rates.time, y: rates.y10, displayName: \"10 Year\")",
"execution_count": null,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Logarithmic Scale"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "The plots support log scale for both axes, independently.\nTo add log scale you need to specify set the logX (for x-axis) or logY (for y-axis) property to true.\nBy default a base 10 is used. To change this, use properties xLogBase and yLogBase."
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "def points = 100;\ndef logBase = 10;\ndef expys = [];\ndef xs = [];\nfor(int i = 0; i < points; i++){\n xs[i] = i / 15.0;\n expys[i] = Math.exp(xs[i]); \n}\n\ndef cplot = new CombinedPlot(xLabel: \"Linear\");\ndef logYPlot = new Plot(title: \"Linear x, Log y\", yLabel: \"Log\", logY: true, yLogBase: logBase);\nlogYPlot << new Line(x: xs, y: expys, displayName: \"f(x) = exp(x)\");\nlogYPlot << new Line(x: xs, y: xs, displayName: \"g(x) = x\");\ncplot.add(logYPlot, 3);\n\n// works for 2nd Y axis too:\n// logYPlot << new YAxis(label: \"Right Log Y-Axis\", log: true, logBase: logBase);\n\ndef linearYPlot = new Plot(title: \"Linear x, Linear y\", yLabel: \"Linear\");\nlinearYPlot << new Line(x: xs, y: expys, displayName: \"f(x) = exp(x)\");\nlinearYPlot << new Line(x: xs, y: xs, displayName: \"g(x) = x\");\ncplot.add(linearYPlot, 3);\n\ncplot",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "def points = 100;\ndef logBase = 10;\ndef expys = [];\ndef xs = [];\nfor(int i = 0; i < points; i++){\n xs[i] = i /15\n expys[i] = Math.exp(xs[i]);\n}\n\ndef plot = new Plot(title: \"Log x, Log y\", xLabel: \"Log\", yLabel: \"Log\",\n logX: true, xLogBase: logBase, logY: true, yLogBase: logBase);\n\nplot << new Line(x: xs, y: expys, displayName: \"f(x) = exp(x)\");\nplot << new Line(x: xs, y: xs, displayName: \"f(x) = x\");\n\nplot",
"execution_count": null,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Date Objects for the Time Coordinate"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "For Time plots you can provide x coordinate as:\n\n* a list of numbers (milliseconds), or\n* a list of java.util.Date objects, or\n* a list of java.util.Calendar objects, or\n* a list of java.time.Instant objects, or\n* a list of java.time.LocalDateTime objects, or\n* a list of java.time.LocalTime objects."
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "def cal = Calendar.getInstance();\ncal.add(Calendar.HOUR, -1)\n\ndef today = new Date();\ndef millis = today.time;\ndef hour = 1000 * 60 * 60;\n\ndef plot = new TimePlot(\n timeZone: new SimpleTimeZone(10800000, \"America/New_York\")\n);\n//list of milliseconds\nplot << new Points(x:(0..10).collect{millis + hour * it}, y:(0..10), size: 10, displayName: \"milliseconds\");\n//list of java.util.Date objects\nplot << new Points(x:(0..10).collect{cal.add(Calendar.HOUR, 1); cal.getTime()}, y:(0..10), size: 4, displayName: \"date objects\");",
"execution_count": null,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Nanosecond Resolution"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "Handling time with nanosecond resolution is easy in languages like Java and Groovy because they support 64-bit integers.\nNumbers in JavaScript however are limited to 53 bits. Beaker's plotting library can handle these large numbers, just use the NanoPlot class."
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "def today = new Date()\ndef millis = today.time\ndef nanos = millis * 1000 * 1000g // g makes it arbitrary precision\ndef np = new NanoPlot()\nnp << new Points(x:(0..10).collect{nanos + 7 * it}, y:(0..10))",
"execution_count": null,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## More Formatting Controls"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "You can remove the tick labels from either or both axes."
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "p = new Plot(title: \"No Tick Labels\", xTickLabelsVisible: false, yTickLabelsVisible: false)\np << new Line([0, 1, 6, 5, 2, 8])",
"execution_count": null,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "And add arbitrary styles to various elements:"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "r = new Random()\np = new Plot(title: \"Advanced Plot Styling\",\n labelStyle: \"font-size:32px; font-weight: bold; font-family: courier; fill: green;\",\n gridLineStyle: \"stroke: purple; stroke-width: 3;\",\n titleStyle: \"color: green;\"\n )\np << new Points(x: (1..1000).collect { r.nextGaussian() * 10.0d },\n y: (1..1000).collect { r.nextGaussian() * 20.0d })",
"execution_count": null,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Rasters"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "import java.nio.file.Files\nbyte[] picture = Files.readAllBytes(new File(\"../resources/img/widgetArch.png\").toPath());\ndef p = new Plot();\n// x y width height are coordinates, opacity is a double in 0~1\n\n// image can be loaded via bytes, filepath, or url\np << new Rasters(x: [-10,3], y: [3,1.5], width: [6,5], height:[10,8], opacity: [1,0.5], dataString: picture);\n//p << new Rasters(x: -1, y: 4.5, width: 5, height: 8, opacity:0.5, filePath: \"../resources/img/widgetArch.png\");\np << new Rasters(x: [-4], y: [10.5], width: [7], height: [2], opacity:[1], fileUrl: \"https://www.twosigma.com/static/img/twosigma.png\");\n\n// a list of images!\ndef x = [-8, -5, -3, -2, -1, 1, 2, 4, 6, 8]\ndef y = [4, 5, 1, 2, 0 ,3, 6, 4, 5, 9]\ndef width = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\ndef opacity = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1]\np << new Rasters(x: x, y: y, width:width, height:width, opacity:opacity,fileUrl: \"http://icons.iconarchive.com/icons/paomedia/small-n-flat/1024/sign-check-icon.png\")\n",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "def plot = new Plot(title: \"Setting 2nd Axis bounds\")\ndef ys = [0, 2, 4, 6, 15, 10]\ndef ys2 = [-40, 50, 6, 4, 2, 0]\ndef ys3 = [3, 6, 3, 6, 70, 6]\nplot << new YAxis(label:\"Spread\")\nplot << new Line(y: ys)\nplot << new Line(y: ys2, yAxis: \"Spread\")\nplot.getYAxes()[0].setBound(1,5);\nplot.getYAxes()[1].setBound(3,6) // this should change the bounds of the 2nd, right axis\nplot",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "new Line(y: [4, 0], x: [0, 5])",
"execution_count": null,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Y Axis 0 point auto inclusion\nYou can include `y: 0` point by using yAutoRangeIncludesZero property."
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "new Plot(yAutoRangeIncludesZero: true) << new Line(y: [5, 10])",
"execution_count": null,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Limit X and Y Bounds"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "new Plot(xBound: [7, 9], yBound: [6, 9]) << new Line(x: (1..8), y: (1..8)) << new Line(x: (8..10), y: [8, 7, 6])",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "new Plot(xBound: [7, 9]) << new Line(x: (1..8), y: (1..8)) << new Line(x: (8..10), y: [8, 7, 6])",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "new Plot(yBound: [6, 9]) << new Line(x: (1..8), y: (1..8)) << new Line(x: (8..10), y: [8, 7, 6])",
"execution_count": null,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Margins\nYou can add margins to the plot using:\n\n- xLowerMargin, \n- xUpperMargin, \n- yLowerMargin, \n- yUpperMargin \n\nproperties."
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "p = new Plot(title: \"Margins\", \n xLowerMargin: 1, xUpperMargin: 1, \n yLowerMargin: 1, yUpperMargin: 1) \np << new Line(x: (1..10), y: (5..14))",
"execution_count": null,
"outputs": []
}
],
"metadata": {
"kernelspec": {
"name": "groovy",
"display_name": "Groovy",
"language": "groovy"
},
"language_info": {
"nbconverter_exporter": "",
"codemirror_mode": "groovy",
"name": "Groovy",
"mimetype": "",
"file_extension": ".groovy",
"version": "2.4.3"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"version_major": 2,
"version_minor": 0,
"state": {
"201047f6-42dc-4c01-b76a-a04ce506fab8": {
"model_name": "PlotModel",
"model_module": "beakerx",
"model_module_version": "*",
"state": {}
},
"b64bf1e3-64a4-4b02-968e-3888a70e16c8": {
"model_name": "PlotModel",
"model_module": "beakerx",
"model_module_version": "*",
"state": {}
},
"e4a13b65-5b44-41ce-9f19-00db43159acd": {
"model_name": "PlotModel",
"model_module": "beakerx",
"model_module_version": "*",
"state": {}
},
"dd5f5356-c4fb-49f0-a4f2-b11c9cbf034c": {
"model_name": "PlotModel",
"model_module": "beakerx",
"model_module_version": "*",
"state": {
"model": {
"type": "Plot",
"init_width": 640,
"init_height": 480,
"chart_title": null,
"show_legend": null,
"use_tool_tip": true,
"legend_position": {
"type": "LegendPosition",
"position": "TOP_RIGHT"
},
"legend_layout": "VERTICAL",
"custom_styles": [],
"element_styles": {},
"domain_axis_label": null,
"y_label": "",
"rangeAxes": [
{
"type": "YAxis",
"label": "",
"auto_range": true,
"auto_range_includes_zero": false,
"lower_margin": 0,
"upper_margin": 0,
"lower_bound": 0,
"upper_bound": 0,
"use_log": false,
"log_base": 10
}
],
"x_lower_margin": 0.05,
"x_upper_margin": 0.05,
"y_auto_range": true,
"y_auto_range_includes_zero": false,
"y_lower_margin": 0,
"y_upper_margin": 0,
"y_lower_bound": 0,
"y_upper_bound": 0,
"log_y": false,
"timezone": null,
"crosshair": null,
"omit_checkboxes": false,
"graphics_list": [
{
"type": "Line",
"uid": "eb7049f4-3cac-4f3d-ac5f-259c5f78c7f9",
"visible": true,
"yAxis": null,
"hasClickAction": false,
"x": [
0,
1,
2,
3,
4,
5
],
"y": [
0,
1,
6,
5,
2,
8
],
"display_name": "",
"width": 1.5
}
],
"constant_lines": [],
"constant_bands": [],
"rasters": [],
"texts": [],
"x_auto_range": true,
"x_lower_bound": 0,
"x_upper_bound": 0,
"log_x": false,
"x_log_base": 10,
"x_tickLabels_visible": true,
"y_tickLabels_visible": true,
"numberOfPoints": 6,
"outputPointsLimit": 1000000,
"outputPointsPreviewNumber": 10000,
"tips": {}
}
}
},
"7c37e610-f9e1-4516-9bbe-080719c5860c": {
"model_name": "PlotModel",
"model_module": "beakerx",
"model_module_version": "*",
"state": {
"model": {
"type": "Plot",
"init_width": 640,
"init_height": 480,
"chart_title": "We Will Control the Title",
"show_legend": null,
"use_tool_tip": true,
"legend_position": {
"type": "LegendPosition",
"position": "TOP_RIGHT"
},
"legend_layout": "VERTICAL",
"custom_styles": [],
"element_styles": {},
"domain_axis_label": "Horizontal",
"y_label": "Vertical",
"rangeAxes": [
{
"type": "YAxis",
"label": "Vertical",
"auto_range": true,
"auto_range_includes_zero": false,
"lower_margin": 0,
"upper_margin": 0,
"lower_bound": 0,
"upper_bound": 0,
"use_log": false,
"log_base": 10
}
],
"x_lower_margin": 0.05,
"x_upper_margin": 0.05,
"y_auto_range": true,
"y_auto_range_includes_zero": false,
"y_lower_margin": 0,
"y_upper_margin": 0,
"y_lower_bound": 0,
"y_upper_bound": 0,
"log_y": false,
"timezone": null,
"crosshair": null,
"omit_checkboxes": false,
"graphics_list": [],
"constant_lines": [],
"constant_bands": [],
"rasters": [],
"texts": [],
"x_auto_range": true,
"x_lower_bound": 0,
"x_upper_bound": 0,
"log_x": false,
"x_log_base": 10,
"x_tickLabels_visible": true,
"y_tickLabels_visible": true,
"numberOfPoints": null,
"outputPointsLimit": 1000000,
"outputPointsPreviewNumber": 10000,
"tips": {}
}
}
}
}
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment