{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Category Plots, aka Bar Charts" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from beakerx import *\n", "bars = CategoryBars(value= [[1, 2, 3], [1, 3, 5]])\n", "plot = CategoryPlot()\n", "\n", "plot.add(bars)\n", "plot" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cplot = CategoryPlot(initWidth= 400, initHeight= 200)\n", "bars = CategoryBars(value=[[1, 2, 3], [1, 3, 5]])\n", "cplot.add(bars)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cplot = CategoryPlot(title= \"Hello CategoryPlot!\",\n", " xLabel= \"Categories\",\n", " yLabel= \"Values\")\n", "cplot.add(CategoryBars(value=[[1, 2, 3], [1, 3, 5]]))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cplot = CategoryPlot(categoryNames= [\"Helium\", \"Neon\", \"Argon\"])\n", "cplot.add(CategoryBars(value= [[1, 2, 3], [1, 3, 5]]))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "CategoryPlot().add(CategoryBars(value= [[1, 2, 3], [1, 3, 5]],\n", " seriesNames= [\"Gas\", \"Liquid\"]))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "bars = CategoryBars(value= [[1, 2], [3, 4], [5, 6], [7, 8]],\n", " seriesNames= [\"Gas\", None, \"\", \"Liquid\"])\n", "CategoryPlot().add(bars)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot = CategoryPlot(showLegend= True) # force legend display\n", "bars = CategoryBars(value= [[1, 2, 3], [1, 3, 5]])\n", "# since no display names were provided, default names \"series0\" etc will be used.\n", "plot.add(bars)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot = CategoryPlot(orientation= PlotOrientationType.HORIZONTAL)\n", "plot.add(CategoryBars(value=[[1, 2, 3], [1, 3, 5]]))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import math\n", "plot = CategoryPlot(categoryNames= [\"Acid\", \"Neutral\", \"Base\"], \n", " categoryNamesLabelAngle= -1/4 * math.pi)\n", "plot.add(CategoryBars(value= [[1, 2, 3], [4, 5, 6]]))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "CategoryPlot(categoryMargin= 2).add(CategoryBars(value= [[1, 2, 3], [4, 5, 6]]))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#bars = CategoryBars(value= (1..4) + 2)\n", "#CategoryPlot().add(bars)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "bars = CategoryBars(value= [[1, 2], [3, 4], [5, 6]], color= Color.pink)\n", "CategoryPlot().add(bars)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "colors = [Color.red, Color.gray, Color.blue]\n", "bars = CategoryBars(value= [[1, 2], [3, 4], [5, 6]], color= colors)\n", "CategoryPlot().add(bars)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "colors = [[Color.red, Color.gray],\n", " [Color.gray, Color.gray],\n", " [Color.blue, Color.pink]]\n", "bars = CategoryBars(value= [[1, 2], [3, 4], [5, 6]], color= colors)\n", "CategoryPlot().add(bars)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "colors = [Color.pink, [Color.red, Color.gray, Color.blue]]\n", "bars = CategoryBars(value= [[1, 2, 3], [4, 5, 6]], color= colors)\n", "CategoryPlot().add(bars)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "bars = CategoryBars(value= [[1, 2, 3], [4, 5, 6]], base= -2)\n", "CategoryPlot().add(bars)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "bars = CategoryBars(value= [[1, 2, 3], [4, 5, 4]], base= [-1, -3])\n", "CategoryPlot().add(bars)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "bars = CategoryBars(value= [[1, 2, 3], [4, 5, 6]],\n", " base= [[0, 1, 1], [-4, -5, -6]])\n", "CategoryPlot().add(bars)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "bars = CategoryBars(value= [[1, 2, 3], [4, 5, 6]],\n", " width= [[0.3, 0.6, 1.7], 1.0])\n", "CategoryPlot().add(bars)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "bars = CategoryBars(value= [[1, 2, 3], [4, 5, 6]],\n", " fill= [[True, True, False], [True, False, True]],\n", " drawOutline= [[True, False, True], [True, True, False]],\n", " outlineColor= [Color.black, Color.red])\n", "CategoryPlot().add(bars)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "bars = CategoryBars(value= [[1, 2, 3], [4, 5, 8], [10, 9, 10]],\n", " base= [0, [1, 2, 3], [4, 5, 8]],\n", " centerSeries= True,\n", " itemLabel= [[1, 2, 3], [4, 5, 8], [10, 9, 10]]\n", " )\n", "CategoryPlot().add(bars)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ss = [StrokeType.DASH, StrokeType.LONGDASH]\n", "cs = [Color.black, Color.red]\n", "CategoryPlot().add(CategoryStems(value= [[1, 2, 4], [4, 5, 8]], color= cs, style= ss))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "CategoryPlot().add(CategoryPoints(value= [[1, 2, 4], [4, 5, 8]]))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ss = [StrokeType.DASH, StrokeType.DOT]\n", "CategoryPlot().add(CategoryLines(value= [[1, 2, 4], [4, 5, 8]], style= ss,\n", " seriesNames=[\"Lanthanide\", \"Actinide\"]))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "s1 = [1, 2, 4]\n", "s2 = [4, 5, 8]\n", "lines = CategoryLines(value= [s1, s2], centerSeries= True)\n", "points = CategoryPoints(value= [s1, s2], centerSeries= True)\n", "stems = CategoryStems(value=[s1], base= [s2], style= StrokeType.DOT, color= Color.gray)\n", "#plot = CategoryPlot().add(lines).add(points).add(stems)\n", "plot = CategoryPlot()\n", "plot.add(lines)\n", "plot.add(points)\n", "plot.add(stems)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot = CategoryPlot(initWidth= 500, initHeight= 400,\n", " title= \"Bar Chart Demo\",\n", " xLabel= \"Alkali\", yLabel= \"Temperature ° Celcius\",\n", " categoryNames=[\"Lithium\", \"Sodium\", \"Potassium\", \"Rubidium\"])\n", "s1 = [[10, 15, 13, 7], [22, 18, 28, 17]]\n", "high = [[12.4, 19.5, 15.1, 8.2], [24.3, 23.3, 30.1, 18.2]]\n", "low = [[7.6, 10.5, 10.9, 5.8], [19.7, 12.7, 25.9, 15.8]]\n", "color = [Color(247, 150, 70), Color.orange, Color(155, 187, 89)]\n", "plot.add(CategoryBars(value= s1, color= color, seriesNames= [\"Solid\", \"Liquid\"]))\n", "plot.add(CategoryStems(value= high, base= low, color= color[2]))\n", "plot.add(CategoryPoints(value= high, outlineColor= color[2], size=12))\n", "plot.add(CategoryPoints(value= low, outlineColor= color[2], size=12))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "p = CategoryPlot(title= \"Multiple Y Axes Demo\",\n", " yLabel= \"Price\",\n", " categoryNames= [\"Q1\", \"Q2\", \"Q3\", \"Q4\"])\n", "p.add(YAxis(label= \"Volume\", upperMargin= 1))\n", "p.add(CategoryBars(value= [[1500, 2200, 2500, 4000]], width= 0.6,\n", " color= Color.PINK, yAxis= \"Volume\", showItemLabel= True,\n", " labelPosition= LabelPositionType.VALUE_INSIDE))\n", "p.add(CategoryLines(value= [[5, 2, 3.5, 4]], color= Color.GRAY,\n", " showItemLabel=True))\n", "p.add(CategoryPoints(value=[[5, 2, 3.5, 4]], color=Color.GRAY))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "CategoryPlot().add(CategoryStems(value=[[-3, 2, 4], [4, 5, 8]],\n", " width= 10, showItemLabel= True))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "bars = CategoryBars(value= [[-5, 2, 3], [1, 3, 5]],\n", " showItemLabel= True)\n", "CategoryPlot().add(bars)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "bars = CategoryBars(value= [[-5, 2, 3], [1, 3, 5]],\n", " labelPosition= LabelPositionType.BASE_OUTSIDE,\n", " showItemLabel= True)\n", "CategoryPlot().add(bars)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot = CategoryPlot(title= \"Move mouse cursor over bars\")\n", "bars = CategoryBars(value= [[-5, 2, 3], [1, 3, 5]], useToolTip= False)\n", "plot.add(bars)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#table = [[close=11.59, high=13.15, low=11.92, open=11.92],\n", "# [close=12.76, high=15.44, low=11.88, open=12.42],\n", "# [close=18.19, high=20.96, low=17.93, open=18.56]]\n", "#v = table.collect { it.values().toList() }\n", "#p = CategoryPlot(categoryNames= table[0].keySet().toList())\n", "#p.add(new CategoryBars(value= v, seriesNames= [\"A\", \"B\", \"C\"]))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cs = [Color.orange]\n", "\n", "cp = CategoryPlot() \n", "\n", "cp.add(CategoryArea(value= [[1, 3, 2]], base= [[0.5, 1, 0]]))\n", "cp.add(CategoryArea(value= [[2, 1, 0.5]], color= cs))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.4" } }, "nbformat": 4, "nbformat_minor": 1 }