{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "scrolled": false }, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2\n", "\n", "import numpy as np\n", "import pandas as pd\n", "from IPython.display import display\n", "\n", "import ezhc as hc" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'0.24.2'" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pd.__version__" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'1.16.5'" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.__version__" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Examples\n", "+ reproduced from http://www.highcharts.com/demo/ and http://www.highcharts.com/stock/demo\n", "+ `plot()` has the following arguments:\n", " + `save=True` and optionally `save_name` and optionally `save_path` (default='saved') will save the graph as a stand alone HTML doc under `save_path` after creating it if necessary\n", " + `notebook` (default=True) will not inject `require` and `jquery` libs as they are already available in the classical notebook. Set to False to inject them.\n", " + `version` (default='latest') will specify the highcharts version to use. It is recommended to leave the default value (6.1.2 as of 4sep18).\n", " + `proxy` (default=None') is necessary if you want to check from [highcharts release page](https://github.com/highcharts/highcharts/releases) what the latest version is, and update the list of all past versions. If no proxy is provided, the versions are [hardcoded](https://github.com/oscar6echo/ezhc/blob/64a1afbfae19197bbef8f8c916347df0c8667643/ezhc/_hc_versions.py#L27) in the source code.\n", " \n", "+ `options_as_dict()` will return highchart/highstocks options as a Python dictionary\n", " + args: `chart_id` to specify which div for rendering\n", "\n", "\n", "+ `options_as_json()` will return highchart/highstocks options as json\n", " + args: Same save options as `plot()`\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Times series" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Example 1" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "DatetimeIndex: 15 entries, 2015-01-01 to 2015-01-21\n", "Freq: B\n", "Data columns (total 2 columns):\n", "Track1 15 non-null float64\n", "Track2 15 non-null float64\n", "dtypes: float64(2)\n", "memory usage: 360.0 bytes\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Track1Track2
2015-01-011.0000001.000000
2015-01-020.9955810.993390
2015-01-050.9725161.002118
2015-01-060.9555011.006376
2015-01-070.9735850.989508
\n", "
" ], "text/plain": [ " Track1 Track2\n", "2015-01-01 1.000000 1.000000\n", "2015-01-02 0.995581 0.993390\n", "2015-01-05 0.972516 1.002118\n", "2015-01-06 0.955501 1.006376\n", "2015-01-07 0.973585 0.989508" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Track1Track2
2015-01-150.9069000.981129
2015-01-160.9220570.955343
2015-01-190.9323900.940033
2015-01-200.9221880.934606
2015-01-210.9074040.917937
\n", "
" ], "text/plain": [ " Track1 Track2\n", "2015-01-15 0.906900 0.981129\n", "2015-01-16 0.922057 0.955343\n", "2015-01-19 0.932390 0.940033\n", "2015-01-20 0.922188 0.934606\n", "2015-01-21 0.907404 0.917937" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "df = hc.sample.df_timeseries(N=2, Nb_bd=15+0*3700) #<=473\n", "df.info()\n", "display(df.head())\n", "display(df.tail())" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g = hc.Highstock()\n", "\n", "g.chart.width = 650\n", "g.chart.height = 550\n", "g.legend.enabled = True\n", "g.legend.layout = 'horizontal'\n", "g.legend.align = 'center'\n", "g.legend.maxHeight = 100\n", "g.tooltip.enabled = True\n", "g.tooltip.valueDecimals = 2\n", "g.exporting.enabled = True\n", "\n", "g.chart.zoomType = 'xy'\n", "g.title.text = 'Time series plotted with HighStock'\n", "g.subtitle.text = 'Transparent access to the underlying js lib'\n", "\n", "g.plotOptions.series.compare = 'percent'\n", "g.yAxis.labels.formatter = hc.scripts.FORMATTER_PERCENT\n", "g.tooltip.pointFormat = hc.scripts.TOOLTIP_POINT_FORMAT_PERCENT\n", "g.tooltip.positioner = hc.scripts.TOOLTIP_POSITIONER_CENTER_TOP\n", "\n", "g.xAxis.gridLineWidth = 1.0\n", "g.xAxis.gridLineDashStyle = 'Dot'\n", "g.yAxis.gridLineWidth = 1.0\n", "g.yAxis.gridLineDashStyle = 'Dot'\n", "\n", "g.credits.enabled = True\n", "g.credits.text = 'Source: XXX Flow Strategy & Solutions.'\n", "g.credits.href = 'http://www.example.com'\n", "\n", "g.series = hc.build.series(df)\n", "\n", "g.plot(save=False, version='6.1.2', center=True)\n", "\n", "## IF BEHIND A CORPORATE PROXY\n", "## IF NOT PROXY IS PASSED TO .plot() THEN NO HIGHCHARTS VERSION UPDATE IS PERFORMED\n", "## HARDODED VERSIONS ARE USED INSTEAD\n", "# p = hc.Proxy('mylogin', 'mypwd', 'myproxyhost', 'myproxyport')\n", "# g.plot(save=False, version='latest', proxy=p)\n" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "{'credits': {'enabled': True,\n", " 'text': 'Source: XXX Flow Strategy & Solutions.',\n", " 'href': 'http://www.example.com'},\n", " 'exporting': {'enabled': True},\n", " 'chart': {'animation': False,\n", " 'width': 650,\n", " 'height': 550,\n", " 'zoomType': 'xy',\n", " 'renderTo': 'chart_id'},\n", " 'plotOptions': {'series': {'animation': False, 'compare': 'percent'},\n", " 'line': {'animation': False},\n", " 'column': {'animation': False}},\n", " 'legend': {'enabled': True,\n", " 'layout': 'horizontal',\n", " 'align': 'center',\n", " 'maxHeight': 100},\n", " 'tooltip': {'enabled': True,\n", " 'valueDecimals': 2,\n", " 'pointFormat': '{series.name}: {point.y} ({point.change}%)
',\n", " 'positioner': \"function (labelWidth, labelHeight, point) {\\n var roundUp100 = function(d) { return 100*Math.floor(d/100); },\\n labelWidth = roundUp100(labelWidth),\\n chart = window.charts['__uuid__'];\\n\\n var tooltipX, tooltipY;\\n var testX = (point.plotX + labelWidth * 0.7 > chart.plotWidth / 2) && (point.plotX - labelWidth * 0.7 < chart.plotWidth / 2);\\n var testY = point.plotY < labelHeight * 0.7;\\n\\n if (testX && testY) {\\n tooltipX = chart.plotLeft + (chart.plotWidth - labelWidth) / 2;\\n tooltipY = chart.plotTop + chart.plotHeight - labelHeight;\\n } else {\\n tooltipX = chart.plotLeft + (chart.plotWidth - labelWidth) / 2;\\n tooltipY = chart.plotTop;\\n }\\n\\n return {\\n x: tooltipX,\\n y: tooltipY\\n };\\n}\\n\\n\"},\n", " 'title': {'text': 'Time series plotted with HighStock'},\n", " 'subtitle': {'text': 'Transparent access to the underlying js lib'},\n", " 'yAxis': {'labels': {'formatter': \"function() { return (this.value > 0 ? ' + ' : '') + this.value + '%'; }\\n\"},\n", " 'gridLineWidth': 1.0,\n", " 'gridLineDashStyle': 'Dot'},\n", " 'xAxis': {'gridLineWidth': 1.0, 'gridLineDashStyle': 'Dot'},\n", " 'series': [{'name': 'Track1',\n", " 'yAxis': 0,\n", " 'data': [[Timestamp('2015-01-01 00:00:00', freq='B'), 1.0],\n", " [Timestamp('2015-01-02 00:00:00', freq='B'), 0.9955809138122033],\n", " [Timestamp('2015-01-05 00:00:00', freq='B'), 0.9725156536640029],\n", " [Timestamp('2015-01-06 00:00:00', freq='B'), 0.9555008659684235],\n", " [Timestamp('2015-01-07 00:00:00', freq='B'), 0.9735852580931271],\n", " [Timestamp('2015-01-08 00:00:00', freq='B'), 0.9709321132210923],\n", " [Timestamp('2015-01-09 00:00:00', freq='B'), 0.9726862121296252],\n", " [Timestamp('2015-01-12 00:00:00', freq='B'), 0.9570236218094534],\n", " [Timestamp('2015-01-13 00:00:00', freq='B'), 0.9442796901261044],\n", " [Timestamp('2015-01-14 00:00:00', freq='B'), 0.9139256061055365],\n", " [Timestamp('2015-01-15 00:00:00', freq='B'), 0.9069001469685026],\n", " [Timestamp('2015-01-16 00:00:00', freq='B'), 0.9220566792158227],\n", " [Timestamp('2015-01-19 00:00:00', freq='B'), 0.9323895174200195],\n", " [Timestamp('2015-01-20 00:00:00', freq='B'), 0.9221882459625789],\n", " [Timestamp('2015-01-21 00:00:00', freq='B'), 0.907404366111972]]},\n", " {'name': 'Track2',\n", " 'yAxis': 0,\n", " 'data': [[Timestamp('2015-01-01 00:00:00', freq='B'), 1.0],\n", " [Timestamp('2015-01-02 00:00:00', freq='B'), 0.9933897589049112],\n", " [Timestamp('2015-01-05 00:00:00', freq='B'), 1.0021180625281059],\n", " [Timestamp('2015-01-06 00:00:00', freq='B'), 1.0063755870959292],\n", " [Timestamp('2015-01-07 00:00:00', freq='B'), 0.9895080760415528],\n", " [Timestamp('2015-01-08 00:00:00', freq='B'), 0.9791839708651677],\n", " [Timestamp('2015-01-09 00:00:00', freq='B'), 0.9808684145393846],\n", " [Timestamp('2015-01-12 00:00:00', freq='B'), 0.9585991659947815],\n", " [Timestamp('2015-01-13 00:00:00', freq='B'), 0.9663917938818657],\n", " [Timestamp('2015-01-14 00:00:00', freq='B'), 0.9724325877021651],\n", " [Timestamp('2015-01-15 00:00:00', freq='B'), 0.9811292493280032],\n", " [Timestamp('2015-01-16 00:00:00', freq='B'), 0.9553434953423843],\n", " [Timestamp('2015-01-19 00:00:00', freq='B'), 0.9400325607426828],\n", " [Timestamp('2015-01-20 00:00:00', freq='B'), 0.934605587680784],\n", " [Timestamp('2015-01-21 00:00:00', freq='B'), 0.9179372034526284]]}]}" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "options_as_dict = g.options_as_dict()\n", "options_as_dict" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'{\"credits\":{\"enabled\":true,\"text\":\"Source: XXX Flow Strategy & Solutions.\",\"href\":\"http:\\\\/\\\\/www.example.com\"},\"exporting\":{\"enabled\":true},\"chart\":{\"animation\":false,\"width\":650,\"height\":550,\"zoomType\":\"xy\",\"renderTo\":\"chart_id\"},\"plotOptions\":{\"series\":{\"animation\":false,\"compare\":\"percent\"},\"line\":{\"animation\":false},\"column\":{\"animation\":false}},\"legend\":{\"enabled\":true,\"layout\":\"horizontal\",\"align\":\"center\",\"maxHeight\":100},\"tooltip\":{\"enabled\":true,\"valueDecimals\":2,\"pointFormat\":\"{series.name}<\\\\/span>: {point.y}<\\\\/b> ({point.change}%)\",\"positioner\":\"function (labelWidth, labelHeight, point) {\\\\n var roundUp100 = function(d) { return 100*Math.floor(d\\\\/100); },\\\\n labelWidth = roundUp100(labelWidth),\\\\n chart = window.charts[\\'__uuid__\\'];\\\\n\\\\n var tooltipX, tooltipY;\\\\n var testX = (point.plotX + labelWidth * 0.7 > chart.plotWidth \\\\/ 2) && (point.plotX - labelWidth * 0.7 < chart.plotWidth \\\\/ 2);\\\\n var testY = point.plotY < labelHeight * 0.7;\\\\n\\\\n if (testX && testY) {\\\\n tooltipX = chart.plotLeft + (chart.plotWidth - labelWidth) \\\\/ 2;\\\\n tooltipY = chart.plotTop + chart.plotHeight - labelHeight;\\\\n } else {\\\\n tooltipX = chart.plotLeft + (chart.plotWidth - labelWidth) \\\\/ 2;\\\\n tooltipY = chart.plotTop;\\\\n }\\\\n\\\\n return {\\\\n x: tooltipX,\\\\n y: tooltipY\\\\n };\\\\n}\\\\n\\\\n\"},\"title\":{\"text\":\"Time series plotted with HighStock\"},\"subtitle\":{\"text\":\"Transparent access to the underlying js lib\"},\"yAxis\":{\"labels\":{\"formatter\":\"function() { return (this.value > 0 ? \\' + \\' : \\'\\') + this.value + \\'%\\'; }\\\\n\"},\"gridLineWidth\":1.0,\"gridLineDashStyle\":\"Dot\"},\"xAxis\":{\"gridLineWidth\":1.0,\"gridLineDashStyle\":\"Dot\"},\"series\":[{\"name\":\"Track1\",\"yAxis\":0,\"data\":[[1420070400000,1.0],[1420156800000,0.9955809138],[1420416000000,0.9725156537],[1420502400000,0.955500866],[1420588800000,0.9735852581],[1420675200000,0.9709321132],[1420761600000,0.9726862121],[1421020800000,0.9570236218],[1421107200000,0.9442796901],[1421193600000,0.9139256061],[1421280000000,0.906900147],[1421366400000,0.9220566792],[1421625600000,0.9323895174],[1421712000000,0.922188246],[1421798400000,0.9074043661]]},{\"name\":\"Track2\",\"yAxis\":0,\"data\":[[1420070400000,1.0],[1420156800000,0.9933897589],[1420416000000,1.0021180625],[1420502400000,1.0063755871],[1420588800000,0.989508076],[1420675200000,0.9791839709],[1420761600000,0.9808684145],[1421020800000,0.958599166],[1421107200000,0.9663917939],[1421193600000,0.9724325877],[1421280000000,0.9811292493],[1421366400000,0.9553434953],[1421625600000,0.9400325607],[1421712000000,0.9346055877],[1421798400000,0.9179372035]]}]}'" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "options_as_json = g.options_as_json()\n", "options_as_json" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Example 2" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "scrolled": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Track1Track2Track3Cash
2015-01-011.0000001.0000001.0000001.000077
2015-01-020.9955811.0053480.9669491.000154
2015-01-050.9725161.0108490.9899691.000231
2015-01-060.9555011.0295560.9828791.000308
2015-01-070.9735851.0168240.9736651.000385
\n", "
" ], "text/plain": [ " Track1 Track2 Track3 Cash\n", "2015-01-01 1.000000 1.000000 1.000000 1.000077\n", "2015-01-02 0.995581 1.005348 0.966949 1.000154\n", "2015-01-05 0.972516 1.010849 0.989969 1.000231\n", "2015-01-06 0.955501 1.029556 0.982879 1.000308\n", "2015-01-07 0.973585 1.016824 0.973665 1.000385" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Track1Track2Track3Cash
2022-08-250.5297551.5236840.8247041.165946
2022-08-260.5390181.5382760.8200191.166035
2022-08-290.5406581.5366330.8123211.166125
2022-08-300.5555691.5324760.8184231.166215
2022-08-310.5460181.5065160.8283841.166305
\n", "
" ], "text/plain": [ " Track1 Track2 Track3 Cash\n", "2022-08-25 0.529755 1.523684 0.824704 1.165946\n", "2022-08-26 0.539018 1.538276 0.820019 1.166035\n", "2022-08-29 0.540658 1.536633 0.812321 1.166125\n", "2022-08-30 0.555569 1.532476 0.818423 1.166215\n", "2022-08-31 0.546018 1.506516 0.828384 1.166305" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "df = hc.sample.df_timeseries(N=3, Nb_bd=2000)\n", "df['Cash'] = 1.0+0.02/260\n", "df['Cash'] = df['Cash'].cumprod()\n", "display(df.head())\n", "display(df.tail())" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g = hc.Highstock()\n", "\n", "g.chart.height = 550\n", "g.legend.enabled = True\n", "g.legend.layout = 'horizontal'\n", "g.legend.align = 'center'\n", "g.legend.maxHeight = 100\n", "g.tooltip.enabled = True\n", "g.tooltip.valueDecimals = 2\n", "g.exporting.enabled = True\n", "\n", "g.chart.zoomType = 'xy'\n", "g.title.text = 'Time series plotted with HighStock'\n", "g.subtitle.text = 'Transparent access to the underlying js lib'\n", "\n", "g.plotOptions.series.compare = 'percent'\n", "g.yAxis.labels.formatter = hc.scripts.FORMATTER_PERCENT\n", "g.tooltip.pointFormat = hc.scripts.TOOLTIP_POINT_FORMAT_PERCENT\n", "g.tooltip.positioner = hc.scripts.TOOLTIP_POSITIONER_CENTER_TOP\n", "\n", "g.xAxis.gridLineWidth = 1.0\n", "g.xAxis.gridLineDashStyle = 'Dot'\n", "g.yAxis.gridLineWidth = 1.0\n", "g.yAxis.gridLineDashStyle = 'Dot'\n", "\n", "g.credits.enabled = True\n", "g.credits.text = 'Source: XXX Flow Strategy & Solutions.'\n", "g.credits.href = 'http://www.example.com'\n", "\n", "\n", "g.series = hc.build.series(df, visible={'Track3': False})\n", "\n", "\n", "g.plot(save=True, version='6.1.2', save_name='NoTable')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Example 3" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exception\n", "+ The function2 `plot_with_table1()` and `plot_with_table2()` are exceptions with respect to the idea of this module: It is NOT just transparent access to Highchart/Highstock. I added a table (based on datatable.net) to display more data about the period selected. This measurements cannot be calculated beforehand, so it has to be postprocessing. \n", "+ If `save=True` function `plot_with_table1/2()` will create a standalone HTML file containing the output in subdirectory 'saved'. Optionally `save_name` can be set - an automatic time tag is added to keep things orderly, unless `dated=False`. \n", "+ **NOTE**: Because of css collision between notebook and datatable, the table in the saved file is better looking than in the notebook output area.\n" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "# g.plot_with_table_1(dated=False, version='6.1.2', save=True, save_name='Table1')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Example 4" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Footer\n", "+ A footer can be added to the plot. This is interesting if the plot is saved as a stand alone file.\n", "+ The footer is HTML you can write from scratch but a helper function and a jinja template make it easy.\n", "+ Images are embeded upon save so the saved file is standalone. Only an internet connection is required to download the js libraries." ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
\n", "
\n", "
\n", "
\n", "
\n", "
\n", "
\n", "
\n", "
\n", " Drawdown Number of bdays\n", " \n", " \n", "
\n", "
\n", "
\n", "\n", "
\n", "\n", "
\n", "
\n", "
\n", "
\n", " \n", "
\n", "
\n", " \n", "THE VALUE OF YOUR INVESTMENT MAY FLUCTUATE. \n", "THE FIGURES RELATING TO SIMULATED PAST PERFORMANCES REFER TO PAST \n", "PERIODS AND ARE NOT A RELIABLE INDICATOR OF FUTURE RESULTS. \n", "THIS ALSO APPLIES TO HISTORICAL MARKET DATA.\n", "\n", "
\n", "
" ], "text/plain": [ "" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g.plotOptions.series.compare = 'value'\n", "g.yAxis.labels.formatter = hc.scripts.FORMATTER_BASIC\n", "g.tooltip.pointFormat = hc.scripts.TOOLTIP_POINT_FORMAT_BASIC\n", "g.tooltip.formatter = hc.scripts.FORMATTER_QUANTILE\n", "\n", "disclaimer = \"\"\"\n", "THE VALUE OF YOUR INVESTMENT MAY FLUCTUATE. \n", "THE FIGURES RELATING TO SIMULATED PAST PERFORMANCES REFER TO PAST \n", "PERIODS AND ARE NOT A RELIABLE INDICATOR OF FUTURE RESULTS. \n", "THIS ALSO APPLIES TO HISTORICAL MARKET DATA.\n", "\"\"\"\n", "template_footer = hc.scripts.TEMPLATE_DISCLAIMER\n", "create_footer = hc.scripts.from_template\n", "\n", "logo_path = hc.scripts.PATH_TO_LOGO_SG\n", "# logo_path = 'http://img.talkandroid.com/uploads/2015/11/Chrome-Logo.png'\n", "# logo_path = hc.scripts.image_src('http://img.talkandroid.com/uploads/2015/11/Chrome-Logo.png')\n", "\n", "footer = create_footer(template_footer, comment=disclaimer, img_logo=logo_path)\n", "\n", "g.plot_with_table_2(dated=False, version='6.1.2', save=True, save_name='Table2', footer=footer)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Column, Bar" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
JaneJoeJohn
Fruit
Apples235
Oranges243
Pears344
Grapes227
Bananas152
\n", "
" ], "text/plain": [ " Jane Joe John\n", "Fruit \n", "Apples 2 3 5\n", "Oranges 2 4 3\n", "Pears 3 4 4\n", "Grapes 2 2 7\n", "Bananas 1 5 2" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = hc.sample.df_one_idx_several_col()\n", "df" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g = hc.Highcharts()\n", "\n", "g.chart.type = 'column'\n", "g.chart.width = 500\n", "g.chart.height = 300\n", "# g.plotOptions.column.animation = False\n", "\n", "g.title.text = 'Basic Bar Chart'\n", "g.yAxis.title.text = 'Fruit Consumption'\n", "\n", "g.xAxis.categories = list(df.index)\n", "g.series = hc.build.series(df)\n", "\n", "g.plot(center=True, save=True, version='6.1.2', save_name='test', dated=False)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g.plotOptions.column.stacking = 'normal'\n", "g.title.text = 'Stack Bar Chart'\n", "g.yAxis.title.text = 'Total Fruit Consumption'\n", "\n", "g.plot(version='6.1.2')" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g.plotOptions.column.stacking = 'percent'\n", "g.yAxis.title.text = 'Fruit Consumption Distribution'\n", "\n", "g.plot(version='6.1.2')" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g = hc.Highcharts()\n", "\n", "g.chart.type = 'bar'\n", "g.chart.width = 500\n", "g.chart.height = 400\n", "\n", "g.title.text = 'Basic Bar Chart'\n", "g.xAxis.title.text = 'Fruit Consumption'\n", "\n", "g.xAxis.categories = list(df.index)\n", "g.series = hc.build.series(df)\n", "\n", "g.plot()" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g.plotOptions.bar.stacking = 'normal'\n", "\n", "g.title.text = 'Stacked Bar Chart'\n", "g.xAxis.title.text = 'Total Fruit Consumption'\n", "\n", "g.plot(version='6.1.2')" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g.plotOptions.bar.stacking = 'percent'\n", "\n", "g.title.text = 'Stacked Bar Chart'\n", "g.xAxis.title.text = 'Fruit Consumption Distribution'\n", "\n", "g.plot(version='6.1.2')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Pie" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
MktShare
Brand
Firefox45.0
IE26.8
Chrome12.8
Safari8.5
Opera6.2
Others0.7
\n", "
" ], "text/plain": [ " MktShare\n", "Brand \n", "Firefox 45.0\n", "IE 26.8\n", "Chrome 12.8\n", "Safari 8.5\n", "Opera 6.2\n", "Others 0.7" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = hc.sample.df_one_idx_one_col()\n", "df" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g = hc.Highcharts()\n", "\n", "g.chart.type = 'pie'\n", "g.chart.width = 400\n", "g.chart.height = 400\n", "gpo = g.plotOptions.pie\n", "gpo.showInLegend = True\n", "gpo.dataLabels.enabled = False\n", "\n", "g.title.text = 'Browser Market Share'\n", "\n", "g.series = hc.build.series(df)\n", "\n", "g.plot(version='6.1.2')" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g.chart.width = 400\n", "g.chart.height = 300\n", "\n", "gpo.showInLegend = False\n", "gpo.dataLabels.enabled = True\n", "\n", "gpo.startAngle = -90\n", "gpo.endAngle = 90\n", "gpo.innerSize = '40%'\n", "gpo.center = ['50%', '95%']\n", "\n", "g.plot(version='6.1.2')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Pie, Column Drilldown" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Market Share
BrandVersion
Internet Explorer6.06.40
7.03.55
8.026.70
9.016.96
Firefox2.00.09
\n", "
" ], "text/plain": [ " Market Share\n", "Brand Version \n", "Internet Explorer 6.0 6.40\n", " 7.0 3.55\n", " 8.0 26.70\n", " 9.0 16.96\n", "Firefox 2.0 0.09" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = hc.sample.df_two_idx_one_col()\n", "df.head()" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "scrolled": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g = hc.Highcharts()\n", "\n", "g.chart.type = 'pie'\n", "g.chart.width = 500\n", "g.chart.height = 500\n", "g.exporting = False\n", "gpo = g.plotOptions.pie\n", "gpo.showInLegend = False\n", "gpo.dataLabels.enabled = True\n", "gpo.center = ['50%', '50%']\n", "gpo.size = '65%'\n", "g.drilldown.drillUpButton.position = {'x': 0, 'y': 0}\n", "\n", "g.title.text = 'Browser Market Share'\n", "\n", "g.series, g.drilldown.series = hc.build.series_drilldown(df)\n", "\n", "g.plot(version='6.1.2')" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "scrolled": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g = hc.Highcharts()\n", "\n", "g.chart.type = 'bar'\n", "g.chart.width = 500\n", "g.chart.height = 500\n", "g.exporting = False\n", "gpo = g.plotOptions.pie\n", "gpo.showInLegend = False\n", "gpo.dataLabels.enabled = True\n", "gpo.center = ['50%', '50%']\n", "gpo.size = '65%'\n", "g.drilldown.drillUpButton.position = {'x': 0, 'y': 0}\n", "\n", "g.title.text = 'Browser Market Share'\n", "\n", "g.series, g.drilldown.series = hc.build.series_drilldown(df)\n", "\n", "g.plot()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Pie Drilldown - 3 levels\n", "+ Any number of levels works" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Population
ContinentRegionCountry
AfricaCentral AfricaAngola29784193.0
Cameroon24053727.0
Central African Republic4659080.0
Chad14899994.0
Congo5260750.0
\n", "
" ], "text/plain": [ " Population\n", "Continent Region Country \n", "Africa Central Africa Angola 29784193.0\n", " Cameroon 24053727.0\n", " Central African Republic 4659080.0\n", " Chad 14899994.0\n", " Congo 5260750.0" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = hc.sample.df_several_idx_one_col_2()\n", "df.head()" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Population
ContinentRegionCountry
AfricaCentral AfricaAngola29784193.0
Cameroon24053727.0
Central African Republic4659080.0
Chad14899994.0
Congo5260750.0
Democratic Republic of the Congo81339988.0
Equatorial Guinea1267689.0
Gabon2025137.0
Sao Tome and Principe204327.0
Eastern AfricaBurundi10864245.0
Comoros813912.0
Djibouti956985.0
Eritrea5068831.0
Ethiopia104957438.0
Kenya49699862.0
Madagascar25570895.0
Malawi18622104.0
Mauritius1265138.0
Mayotte253045.0
Mozambique29668834.0
Rwanda12208407.0
Réunion876562.0
Seychelles94737.0
Somalia14742523.0
South Sudan12575714.0
Tanzania57310019.0
Uganda42862958.0
Zambia17094130.0
Zimbabwe16529904.0
North AfricaAlgeria41318142.0
............
EuropeWestern EuropeFrance64979548.0
Germany82114224.0
Liechtenstein37922.0
Luxembourg583455.0
Monaco38695.0
Netherlands17035938.0
Switzerland8476005.0
OceanicAustralia and New ZealandAustralia24450561.0
New Zealand4705818.0
MelanesiaFiji905502.0
New Caledonia276255.0
Papua New GuineaNaN
Solomon Islands611343.0
Vanuatu276244.0
MicronesiaFederated States of Micronesia105544.0
Guam164229.0
Kiribati116398.0
Marshall Islands53127.0
Nauru11359.0
Northern Mariana Islands55144.0
Palau21729.0
PolynesiaAmerican Samoa55641.0
Cook Islands17380.0
French Polynesia283007.0
Niue1618.0
Samoa196440.0
Tokelau1300.0
Tonga108020.0
Tuvalu11192.0
Wallis and Futuna11773.0
\n", "

242 rows × 1 columns

\n", "
" ], "text/plain": [ " Population\n", "Continent Region Country \n", "Africa Central Africa Angola 29784193.0\n", " Cameroon 24053727.0\n", " Central African Republic 4659080.0\n", " Chad 14899994.0\n", " Congo 5260750.0\n", " Democratic Republic of the Congo 81339988.0\n", " Equatorial Guinea 1267689.0\n", " Gabon 2025137.0\n", " Sao Tome and Principe 204327.0\n", " Eastern Africa Burundi 10864245.0\n", " Comoros 813912.0\n", " Djibouti 956985.0\n", " Eritrea 5068831.0\n", " Ethiopia 104957438.0\n", " Kenya 49699862.0\n", " Madagascar 25570895.0\n", " Malawi 18622104.0\n", " Mauritius 1265138.0\n", " Mayotte 253045.0\n", " Mozambique 29668834.0\n", " Rwanda 12208407.0\n", " Réunion 876562.0\n", " Seychelles 94737.0\n", " Somalia 14742523.0\n", " South Sudan 12575714.0\n", " Tanzania 57310019.0\n", " Uganda 42862958.0\n", " Zambia 17094130.0\n", " Zimbabwe 16529904.0\n", " North Africa Algeria 41318142.0\n", "... ...\n", "Europe Western Europe France 64979548.0\n", " Germany 82114224.0\n", " Liechtenstein 37922.0\n", " Luxembourg 583455.0\n", " Monaco 38695.0\n", " Netherlands 17035938.0\n", " Switzerland 8476005.0\n", "Oceanic Australia and New Zealand Australia 24450561.0\n", " New Zealand 4705818.0\n", " Melanesia Fiji 905502.0\n", " New Caledonia 276255.0\n", " Papua New Guinea NaN\n", " Solomon Islands 611343.0\n", " Vanuatu 276244.0\n", " Micronesia Federated States of Micronesia 105544.0\n", " Guam 164229.0\n", " Kiribati 116398.0\n", " Marshall Islands 53127.0\n", " Nauru 11359.0\n", " Northern Mariana Islands 55144.0\n", " Palau 21729.0\n", " Polynesia American Samoa 55641.0\n", " Cook Islands 17380.0\n", " French Polynesia 283007.0\n", " Niue 1618.0\n", " Samoa 196440.0\n", " Tokelau 1300.0\n", " Tonga 108020.0\n", " Tuvalu 11192.0\n", " Wallis and Futuna 11773.0\n", "\n", "[242 rows x 1 columns]" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df" ] }, { "cell_type": "code", "execution_count": 27, "metadata": { "scrolled": false }, "outputs": [], "source": [ "# g = hc.Highcharts()\n", "\n", "# g.chart.type = 'pie'\n", "# g.chart.width = 500\n", "# g.chart.height = 500\n", "# g.exporting = False\n", "# gpo = g.plotOptions.pie\n", "# gpo.showInLegend = False\n", "# gpo.dataLabels.enabled = True\n", "# gpo.center = ['50%', '50%']\n", "# gpo.size = '65%'\n", "# g.drilldown.drillUpButton.position = {'x': 0, 'y': 0}\n", "\n", "# g.title.text = 'World Population'\n", "\n", "# g.series, g.drilldown.series = hc.build.series_drilldown(df, top_name='World')\n", "\n", "# # g.plot(version='6.1.2')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Column Range" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
MinMax
Month
Jan-9.79.4
Feb-8.76.5
Mar-3.59.4
Apr-1.419.9
May0.022.6
\n", "
" ], "text/plain": [ " Min Max\n", "Month \n", "Jan -9.7 9.4\n", "Feb -8.7 6.5\n", "Mar -3.5 9.4\n", "Apr -1.4 19.9\n", "May 0.0 22.6" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = hc.sample.df_one_idx_two_col()\n", "df.head()" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g = hc.Highcharts()\n", "g.chart.type = 'columnrange'\n", "g.chart.inverted = True\n", "g.chart.width = 700\n", "g.chart.height = 400\n", "gpo = g.plotOptions.columnrange\n", "gpo.dataLabels.enabled = True\n", "gpo.dataLabels.formatter = 'function() { return this.y + \"°C\"; }'\n", "g.tooltip.valueSuffix = '°C'\n", "g.xAxis.categories, g.series = hc.build.series_range(df)\n", "g.series[0]['name'] = 'Temperature'\n", "g.yAxis.title.text = 'Temperature (°C)'\n", "g.xAxis.title.text = 'Month'\n", "g.title.text = 'Temperature Variations by Month'\n", "g.subtitle.text = 'Vik, Norway'\n", "\n", "g.legend.enabled = False\n", "\n", "g.plot(save=True, save_name='index', version='6.1.2', dated=False, notebook=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Scatter - 1" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Sex
HeightWeight
161.251.6Female
167.559.0Female
159.549.2Female
157.063.0Female
155.853.6Female
\n", "
" ], "text/plain": [ " Sex\n", "Height Weight \n", "161.2 51.6 Female\n", "167.5 59.0 Female\n", "159.5 49.2 Female\n", "157.0 63.0 Female\n", "155.8 53.6 Female" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = hc.sample.df_scatter()\n", "df.head()" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g = hc.Highcharts()\n", "g.chart.type = 'scatter'\n", "g.chart.width = 700\n", "g.chart.height = 500\n", "g.chart.zoomType = 'xy'\n", "g.exporting = False\n", "\n", "g.plotOptions.scatter.marker.radius = 5\n", "\n", "g.tooltip.headerFormat = 'Sex: {series.name}
'\n", "g.tooltip.pointFormat = '{point.x} cm, {point.y} kg'\n", "\n", "g.legend.layout = 'vertical'\n", "g.legend.align = 'left'\n", "g.legend.verticalAlign = 'top'\n", "g.legend.x = 100\n", "g.legend.y = 70\n", "g.legend.floating = True\n", "g.legend.borderWidth = 1\n", " \n", "g.xAxis.title.text = 'Height (cm)'\n", "g.yAxis.title.text = 'Weight (kg)'\n", "g.title.text = 'Height Versus Weight of 507 Individuals by Gender'\n", "g.subtitle.text = 'Source: Heinz 2003'\n", " \n", "g.series = hc.build.series_scatter(df, color_column='Sex',\n", " color={'Female': 'rgba(223, 83, 83, .5)',\n", " 'Male': 'rgba(119, 152, 191, .5)'})\n", "g.plot(version='6.1.2')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Scatter - 2" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
SexTag
HeightWeight
161.251.6Female18990
167.559.0Female57774
159.549.2Female10695
157.063.0Female1706
155.853.6Female64970
\n", "
" ], "text/plain": [ " Sex Tag\n", "Height Weight \n", "161.2 51.6 Female 18990\n", "167.5 59.0 Female 57774\n", "159.5 49.2 Female 10695\n", "157.0 63.0 Female 1706\n", "155.8 53.6 Female 64970" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = hc.sample.df_scatter()\n", "df['Tag'] = np.random.choice(range(int(1e5)), size=len(df), replace=False)\n", "df.head()" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g = hc.Highcharts()\n", "g.chart.type = 'scatter'\n", "g.chart.width = 700\n", "g.chart.height = 500\n", "g.chart.zoomType = 'xy'\n", "g.exporting = False\n", "\n", "g.plotOptions.scatter.marker.radius = 5\n", "\n", "g.tooltip.headerFormat = 'Sex: {series.name}
Tag: {point.key}
'\n", "g.tooltip.pointFormat = '{point.x} cm, {point.y} kg'\n", "\n", "g.legend.layout = 'vertical'\n", "g.legend.align = 'left'\n", "g.legend.verticalAlign = 'top'\n", "g.legend.x = 100\n", "g.legend.y = 70\n", "g.legend.floating = True\n", "g.legend.borderWidth = 1\n", " \n", "g.xAxis.title.text = 'Height (cm)'\n", "g.yAxis.title.text = 'Weight (kg)'\n", "g.title.text = 'Height Versus Weight of 507 Individuals by Gender'\n", "g.subtitle.text = 'Source: Heinz 2003'\n", " \n", "g.series = hc.build.series_scatter(df, color_column='Sex', title_column='Tag',\n", " color={'Female': 'rgba(223, 83, 83, .5)',\n", " 'Male': 'rgba(119, 152, 191, .5)'})\n", "g.plot(version='6.1.2')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Bubble" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Size
Catxy
Cat1973679
947460
687658
648756
682773
\n", "
" ], "text/plain": [ " Size\n", "Cat x y \n", "Cat1 97 36 79\n", " 94 74 60\n", " 68 76 58\n", " 64 87 56\n", " 68 27 73" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = hc.sample.df_bubble()\n", "df.head()" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g = hc.Highcharts()\n", "g.chart.type = 'bubble'\n", "g.chart.width = 700\n", "g.chart.height = 500\n", "g.chart.zoomType = 'xy'\n", "g.plotOptions.bubble.minSize = 20\n", "g.plotOptions.bubble.maxSize = 60\n", "g.legend.enabled = True\n", "g.title.text = 'Bubbles'\n", "\n", "g.series = hc.build.series_bubble(df, color={'A': 'rgba(223, 83, 83, .5)', 'B': 'rgba(119, 152, 191, .5)'})\n", "\n", "g.plot(version='6.1.2')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Treemap\n", "+ Building the points datastructure cannot be wrapped without losing flexibility\n", "+ Example (data and points datastructure taken from http://jsfiddle.net/gh/get/jquery/1.9.1/highslide-software/highcharts.com/tree/master/samples/highcharts/demo/treemap-large-dataset/\n" ] }, { "cell_type": "code", "execution_count": 36, "metadata": { "scrolled": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Value
RegionCountryCause
AfricaAlgeriaCommunicable diseases97.8
Injuries53.8
Noncommunicable diseases710.4
AngolaCommunicable diseases873.3
Injuries137.8
\n", "
" ], "text/plain": [ " Value\n", "Region Country Cause \n", "Africa Algeria Communicable diseases 97.8\n", " Injuries 53.8\n", " Noncommunicable diseases 710.4\n", " Angola Communicable diseases 873.3\n", " Injuries 137.8" ] }, "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = hc.sample.df_several_idx_one_col()\n", "df.head()" ] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[{'name': 'Communicable diseases',\n", " 'value': 97.8,\n", " 'id': '0.0.0.0',\n", " 'parent': '0.0.0'},\n", " {'name': 'Injuries', 'value': 53.8, 'id': '0.0.0.1', 'parent': '0.0.0'},\n", " {'name': 'Noncommunicable diseases',\n", " 'value': 710.4,\n", " 'id': '0.0.0.2',\n", " 'parent': '0.0.0'},\n", " {'name': 'Algeria', 'id': '0.0.0', 'parent': '0.0', 'value': 862.0},\n", " {'name': 'Communicable diseases',\n", " 'value': 873.3,\n", " 'id': '0.0.1.0',\n", " 'parent': '0.0.1'}]" ] }, "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "colors = ['#7cb5ec', '#434348', '#90ed7d', '#f7a35c', '#8085e9',\n", " '#f15c80', '#e4d354', '#2b908f', '#f45b5b', '#91e8e1']\n", "\n", "points = hc.build.series_tree(df, set_color=True, colors=colors, set_value=True, precision=2)\n", "points[:5]" ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g = hc.Highcharts()\n", "\n", "g.chart.type = 'treemap'\n", "g.chart.width = 900\n", "g.chart.height = 600\n", "\n", "g.title.text = 'Global Mortality Rate 2012, per 100 000 population'\n", "g.subtitle.text = 'Click points to drill down.\\nSource: \\\n", " WHO.'\n", "g.exporting = False\n", "\n", "g.series = [{\n", " 'type': \"treemap\",\n", " 'layoutAlgorithm': 'squarified',\n", " 'allowDrillToNode': True,\n", " 'dataLabels': {\n", " 'enabled': False\n", " },\n", " 'levelIsConstant': False,\n", " 'levels': [{\n", " 'level': 1,\n", " 'dataLabels': {\n", " 'enabled': True\n", " },\n", " 'borderWidth': 3\n", " }],\n", " 'data': points,\n", "}]\n", "\n", "g.plot(version='6.1.2')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Sunburst - 2 levels" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Market Share
BrandVersion
Internet Explorer6.06.40
7.03.55
8.026.70
9.016.96
Firefox2.00.09
\n", "
" ], "text/plain": [ " Market Share\n", "Brand Version \n", "Internet Explorer 6.0 6.40\n", " 7.0 3.55\n", " 8.0 26.70\n", " 9.0 16.96\n", "Firefox 2.0 0.09" ] }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = hc.sample.df_two_idx_one_col()\n", "df.head()" ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[{'id': '0', 'name': 'Total'},\n", " {'name': '10', 'value': 0.09, 'id': '0.0.0', 'parent': '0.0'},\n", " {'name': '11', 'value': 0.1, 'id': '0.0.1', 'parent': '0.0'},\n", " {'name': '12', 'value': 0.16, 'id': '0.0.2', 'parent': '0.0'},\n", " {'name': '13', 'value': 0.13, 'id': '0.0.3', 'parent': '0.0'}]" ] }, "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ "points = hc.build.series_tree(df, set_total=True, name_total='Total',\n", " set_color=False,\n", " set_value=False, precision=2)\n", "points[:5]" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g = hc.Highcharts()\n", "\n", "g.chart.type = 'sunburst'\n", "g.title.text = 'Browser Market Share'\n", "g.plotOptions.series.animation = True\n", "g.chart.height = '80%'\n", "g.chart.animation = True\n", "g.exporting = False\n", "g.tooltip = {\n", " 'headerFormat': \"\",\n", " 'pointFormat': '{point.name} Market Share is {point.value:,.3f}'\n", "}\n", "g.series = [{\n", " 'type': 'sunburst',\n", " 'data': points,\n", " 'allowDrillToNode': True,\n", " 'cursor': 'pointer',\n", " 'dataLabels': {\n", " 'format': '{point.name}',\n", " 'filter': {\n", " 'property': 'innerArcLength',\n", " 'operator': '>',\n", " 'value': 16\n", " }\n", " },\n", " 'levels': [{\n", " 'level': 2,\n", " 'colorByPoint': True,\n", " 'dataLabels': {\n", " 'rotationMode': 'parallel'\n", " }\n", " },\n", " {\n", " 'level': 3,\n", " 'colorVariation': {\n", " 'key': 'brightness',\n", " 'to': -0.5\n", " }\n", " }, {\n", " 'level': 4,\n", " 'colorVariation': {\n", " 'key': 'brightness',\n", " 'to': 0.5\n", " }\n", " }]\n", "\n", "}]\n", "\n", "g.plot(version='6.1.2')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Sunburst - 3 levels\n", "+ Any number of levels works" ] }, { "cell_type": "code", "execution_count": 42, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Population
ContinentRegionCountry
AfricaCentral AfricaAngola29784193.0
Cameroon24053727.0
Central African Republic4659080.0
Chad14899994.0
Congo5260750.0
\n", "
" ], "text/plain": [ " Population\n", "Continent Region Country \n", "Africa Central Africa Angola 29784193.0\n", " Cameroon 24053727.0\n", " Central African Republic 4659080.0\n", " Chad 14899994.0\n", " Congo 5260750.0" ] }, "execution_count": 42, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = hc.sample.df_several_idx_one_col_2()\n", "df.head()" ] }, { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[{'id': '0', 'name': 'World'},\n", " {'name': 'Angola', 'value': 29784193.0, 'id': '0.0.0.0', 'parent': '0.0.0'},\n", " {'name': 'Cameroon', 'value': 24053727.0, 'id': '0.0.0.1', 'parent': '0.0.0'},\n", " {'name': 'Central African Republic',\n", " 'value': 4659080.0,\n", " 'id': '0.0.0.2',\n", " 'parent': '0.0.0'},\n", " {'name': 'Chad', 'value': 14899994.0, 'id': '0.0.0.3', 'parent': '0.0.0'}]" ] }, "execution_count": 43, "metadata": {}, "output_type": "execute_result" } ], "source": [ "points = hc.build.series_tree(df, set_total=True, name_total='World',\n", " set_value=False, set_color=False, precision=0)\n", "points[:5]" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 44, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g = hc.Highcharts()\n", "\n", "g.chart.type = 'sunburst'\n", "g.chart.height = '90%'\n", "g.chart.animation = True\n", "g.title.text = 'World population 2017'\n", "g.subtitle.text = 'Source Wikipedia'\n", "g.exporting = False\n", "\n", "g.series = [{\n", " 'type': \"sunburst\",\n", " 'data': points,\n", " 'allowDrillToNode': True,\n", " 'cursor': 'pointer',\n", " 'dataLabels': {\n", " 'format': '{point.name}',\n", " 'filter': {\n", " 'property': 'innerArcLength',\n", " 'operator': '>',\n", " 'value': 16\n", " }\n", " },\n", " 'levels': [{\n", " 'level': 2,\n", " 'colorByPoint': True,\n", " 'dataLabels': {\n", " 'rotationMode': 'parallel'\n", " }\n", " },\n", " {\n", " 'level': 3,\n", " 'colorVariation': {\n", " 'key': 'brightness',\n", " 'to': -0.5\n", " }\n", " }, {\n", " 'level': 4,\n", " 'colorVariation': {\n", " 'key': 'brightness',\n", " 'to': 0.5\n", " }\n", " }]\n", "\n", "}]\n", "\n", "g.plot(version='6.1.2')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Polar Chart" ] }, { "cell_type": "code", "execution_count": 45, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
columnlinearea
0811
1728
2632
3547
4453
5366
6274
7185
\n", "
" ], "text/plain": [ " column line area\n", "0 8 1 1\n", "1 7 2 8\n", "2 6 3 2\n", "3 5 4 7\n", "4 4 5 3\n", "5 3 6 6\n", "6 2 7 4\n", "7 1 8 5" ] }, "execution_count": 45, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = pd.DataFrame(data=np.array([[8, 7, 6, 5, 4, 3, 2, 1],\n", " [1, 2, 3, 4, 5, 6, 7, 8],\n", " [1, 8, 2, 7, 3, 6, 4, 5]]).T,\n", " columns=['column', 'line', 'area'])\n", "df" ] }, { "cell_type": "code", "execution_count": 46, "metadata": { "scrolled": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 46, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g = hc.Highcharts()\n", "\n", "g.chart.polar = True\n", "g.chart.width = 500\n", "g.chart.height = 500\n", "\n", "g.title.text = 'Polar Chart'\n", "g.pane.startAngle = 0\n", "g.pane.endAngle = 360\n", "g.pane.background = [{'backgroundColor': '#FFF',\n", " 'borderWidth': 0\n", " }]\n", "\n", "\n", "g.xAxis.tickInterval = 45\n", "g.xAxis.min = 0\n", "g.xAxis.max = 360\n", "g.xAxis.labels.formatter = 'function() { return this.value + \"°\"; }'\n", "g.yAxis.min = 0\n", "\n", "g.plotOptions.series.pointStart = 0\n", "g.plotOptions.series.pointInterval = 45\n", "g.plotOptions.column.pointPadding = 0\n", "g.plotOptions.column.groupPadding = 0\n", "\n", "g.series = [{\n", " 'type': 'column',\n", " 'name': 'Column',\n", " 'data': list(df['column']),\n", " 'pointPlacement': 'between',\n", " }, {\n", " 'type': 'line',\n", " 'name': 'Line',\n", " 'data': list(df['line']),\n", " }, {\n", " 'type': 'area',\n", " 'name': 'Area',\n", " 'data': list(df['area']),\n", " }\n", "]\n", "\n", "g.plot(version='6.1.2')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Spider Web" ] }, { "cell_type": "code", "execution_count": 47, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Allocated BudgetActual Spending
Sales4300050000
Marketing1900039000
Development6000042000
Customer Support3500031000
Information Technology1700026000
Administration1000014000
\n", "
" ], "text/plain": [ " Allocated Budget Actual Spending\n", "Sales 43000 50000\n", "Marketing 19000 39000\n", "Development 60000 42000\n", "Customer Support 35000 31000\n", "Information Technology 17000 26000\n", "Administration 10000 14000" ] }, "execution_count": 47, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = pd.DataFrame(data=np.array([[43000, 19000, 60000, 35000, 17000, 10000],\n", " [50000, 39000, 42000, 31000, 26000, 14000]]).T,\n", " columns=['Allocated Budget', 'Actual Spending'],\n", " index = ['Sales', 'Marketing', 'Development', 'Customer Support',\n", " 'Information Technology', 'Administration'])\n", "df" ] }, { "cell_type": "code", "execution_count": 48, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 48, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g = hc.Highcharts()\n", "\n", "g.chart.polar = True\n", "g.chart.width = 650\n", "g.chart.height = 500\n", "\n", "g.title.text = 'Budget vs. Spending'\n", "g.title.x = -80\n", "\n", "g.pane.size = '80%'\n", "g.pane.background = [{'backgroundColor': '#FFF',\n", " 'borderWidth': 0\n", " }]\n", "\n", "g.xAxis.tickmarkPlacement = 'on'\n", "g.xAxis.lineWidth = 0\n", "g.xAxis.categories = list(df.index)\n", "\n", "g.yAxis.min = 0\n", "g.yAxis.lineWidth = 0\n", "g.yAxis.gridLineInterpolation = 'polygon'\n", "\n", "g.tooltip.pointFormat = '{series.name}: ${point.y:,.0f}
'\n", "g.tooltip.shared = True\n", "\n", "\n", "g.legend.align = 'right'\n", "g.legend.verticalAlign = 'top'\n", "g.legend.y = 70\n", "g.legend.layout = 'vertical'\n", "\n", "g.series = [{\n", " 'name': 'Allocated Budget',\n", " 'data': list(df['Allocated Budget']),\n", " 'pointPlacement': 'on'\n", " }, {\n", " 'name': 'Actual Spending',\n", " 'data': list(df['Actual Spending']),\n", " 'pointPlacement': 'on'\n", " },\n", "]\n", "\n", "g.plot(version='6.1.2')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Spider Web DrillDown" ] }, { "cell_type": "code", "execution_count": 49, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "MultiIndex: 49 entries, (Commo Roll-yield, SGICLMFV) to (XA7 Trend, SGIXTFXA)\n", "Data columns (total 2 columns):\n", "5Y 49 non-null float64\n", "1Y 49 non-null float64\n", "dtypes: float64(2)\n", "memory usage: 1.6+ KB\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
5Y1Y
StrategyTicker
Commo Roll-yieldSGICLMFV0.5370450.733342
Commo TrendSGIXTFCY-0.3293530.048283
Credit Short volSGIMCESP-0.308817-0.377703
Credit TrendSGIXGCM-0.309004-0.364754
DefensiveSGBVPHLE0.0131250.361293
SGBVPHQE0.1705900.545278
SGSLQAE-0.226886-0.346204
SGSLQAU-0.169910-0.203781
SGSLQAW-0.176810-0.358769
Div Roll yieldSGBVDRY0.3231950.314904
\n", "
" ], "text/plain": [ " 5Y 1Y\n", "Strategy Ticker \n", "Commo Roll-yield SGICLMFV 0.537045 0.733342\n", "Commo Trend SGIXTFCY -0.329353 0.048283\n", "Credit Short vol SGIMCESP -0.308817 -0.377703\n", "Credit Trend SGIXGCM -0.309004 -0.364754\n", "Defensive SGBVPHLE 0.013125 0.361293\n", " SGBVPHQE 0.170590 0.545278\n", " SGSLQAE -0.226886 -0.346204\n", " SGSLQAU -0.169910 -0.203781\n", " SGSLQAW -0.176810 -0.358769\n", "Div Roll yield SGBVDRY 0.323195 0.314904" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
5Y1Y
StrategyTicker
VIX Roll yieldSGIXVIDC0.2011220.264023
ValueSGBVPHVE0.2257440.599609
SGSLVAE0.1507230.413127
SGSLVAU0.171771-0.410886
SGSLVAW0.031459-0.061792
Value/DefensiveSGSLVQAE-0.203975-0.791955
SGSLVQAU0.004480-0.284006
SGSLVQAW-0.143451-0.280947
XA7 Dual MomSGBVCADM0.0820670.478879
XA7 TrendSGIXTFXA-0.1073910.281111
\n", "
" ], "text/plain": [ " 5Y 1Y\n", "Strategy Ticker \n", "VIX Roll yield SGIXVIDC 0.201122 0.264023\n", "Value SGBVPHVE 0.225744 0.599609\n", " SGSLVAE 0.150723 0.413127\n", " SGSLVAU 0.171771 -0.410886\n", " SGSLVAW 0.031459 -0.061792\n", "Value/Defensive SGSLVQAE -0.203975 -0.791955\n", " SGSLVQAU 0.004480 -0.284006\n", " SGSLVQAW -0.143451 -0.280947\n", "XA7 Dual Mom SGBVCADM 0.082067 0.478879\n", "XA7 Trend SGIXTFXA -0.107391 0.281111" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "df = hc.sample.df_two_idx_several_col()\n", "df.info()\n", "display(df.head(10))\n", "display(df.tail(10))" ] }, { "cell_type": "code", "execution_count": 50, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 50, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g = hc.Highcharts()\n", "\n", "# g.chart.type = 'column'\n", "g.chart.polar = True\n", "g.plotOptions.series.animation = True\n", "\n", "g.chart.width = 950\n", "g.chart.height = 700\n", "g.pane.size = '90%'\n", "\n", "g.title.text = 'Perf (%) Contrib by Strategy & Period'\n", "\n", "g.xAxis.type = 'category'\n", "g.xAxis.tickmarkPlacement = 'on'\n", "g.xAxis.lineWidth = 0\n", "\n", "g.yAxis.gridLineInterpolation = 'polygon'\n", "g.yAxis.lineWidth = 0\n", "g.yAxis.plotLines = [{'color': 'gray', 'value': 0, 'width': 1.5}]\n", "\n", "g.tooltip.pointFormat = '{series.name}: {point.y:,.3f}%
'\n", "g.tooltip.shared = False\n", "\n", "g.legend.enabled = True\n", "g.legend.align = 'right'\n", "g.legend.verticalAlign = 'top'\n", "g.legend.y = 70\n", "g.legend.layout = 'vertical'\n", "\n", "# color names from http://www.w3schools.com/colors/colors_names.asp \n", "# color rgba() codes from http://www.hexcolortool.com/\n", "g.series, g.drilldown.series = hc.build.series_drilldown(df, colorByPoint=False,\n", " color={'5Y': 'indigo'},\n", "# color={'5Y': 'rgba(136, 110, 166, 1)'}\n", " )\n", "\n", "g.plot(save=True, save_name='ContribTable', version='6.1.2')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Box Plot" ] }, { "cell_type": "code", "execution_count": 51, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
01234
A760801848895965
B7338539399801080
C714762817870918
D724802806871950
E834836864882910
\n", "
" ], "text/plain": [ " 0 1 2 3 4\n", "A 760 801 848 895 965\n", "B 733 853 939 980 1080\n", "C 714 762 817 870 918\n", "D 724 802 806 871 950\n", "E 834 836 864 882 910" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
01
00644
14718
24951
34969
\n", "
" ], "text/plain": [ " 0 1\n", "0 0 644\n", "1 4 718\n", "2 4 951\n", "3 4 969" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "df_obs = pd.DataFrame(data=np.array([[760, 801, 848, 895, 965],\n", " [733, 853, 939, 980, 1080],\n", " [714, 762, 817, 870, 918],\n", " [724, 802, 806, 871, 950],\n", " [834, 836, 864, 882, 910]]),\n", " index=list('ABCDE'))\n", "display(df_obs)\n", "\n", "# x, y positions where 0 is the first category\n", "df_outlier = pd.DataFrame(data=np.array([[0, 644],\n", " [4, 718],\n", " [4, 951],\n", " [4, 969]]))\n", "\n", "\n", "display(df_outlier)\n", "\n", "colors = ['#7cb5ec', '#434348', '#90ed7d', '#f7a35c', '#8085e9',\n", " '#f15c80', '#e4d354', '#2b908f', '#f45b5b', '#91e8e1']" ] }, { "cell_type": "code", "execution_count": 52, "metadata": { "scrolled": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 52, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g = hc.Highcharts()\n", "\n", "g.chart.type = 'boxplot'\n", "g.chart.width = 850\n", "g.chart.height = 500\n", "\n", "g.title.text = 'Box Plot Example'\n", "\n", "g.legend.enabled = False\n", "\n", "g.xAxis.categories = list(df_obs.index)\n", "g.xAxis.title.text = 'Experiment'\n", "\n", "g.yAxis.title.text = 'Observations'\n", "g.yAxis.plotLines= [{\n", " 'value': 932,\n", " 'color': 'red',\n", " 'width': 1,\n", " 'label': {\n", " 'text': 'Theoretical mean: 932',\n", " 'align': 'center',\n", " 'style': { 'color': 'gray' }\n", " }\n", "}]\n", "\n", "g.series = []\n", "g.series.append({\n", " 'name': 'Observations',\n", " 'data': list(df_obs.values),\n", " 'tooltip': { 'headerFormat': 'Experiment No {point.key}
' },\n", "})\n", "g.series.append({\n", " 'name': 'Outlier',\n", " 'color': colors[0],\n", " 'type': 'scatter',\n", " 'data': list(df_outlier.values),\n", " 'marker': {\n", " 'fillColor': 'white',\n", " 'lineWidth': 1,\n", " 'lineColor': colors[0],\n", " },\n", " 'tooltip': { 'pointFormat': 'Observation: {point.y}' }\n", "})\n", "\n", "g.plot(version='6.1.2')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Heatmap" ] }, { "cell_type": "code", "execution_count": 53, "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
AlexanderMarieMaximilianSophiaLukasMariaLeonAnnaTimLaura
WeekDay
Monday10923572388813318547
Tuesday19581513253244197114
Wednesday878123114812888212331
Thursday241176419117698326448
Friday6748521611512096308491
\n", "
" ], "text/plain": [ " Alexander Marie Maximilian Sophia Lukas Maria Leon Anna \\\n", "WeekDay \n", "Monday 10 92 35 72 38 88 13 31 \n", "Tuesday 19 58 15 132 5 32 44 1 \n", "Wednesday 8 78 123 114 8 12 88 82 \n", "Thursday 24 117 64 19 117 6 98 32 \n", "Friday 67 48 52 16 115 120 96 30 \n", "\n", " Tim Laura \n", "WeekDay \n", "Monday 85 47 \n", "Tuesday 97 114 \n", "Wednesday 123 31 \n", "Thursday 64 48 \n", "Friday 84 91 " ] }, "execution_count": 53, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = hc.sample.df_one_idx_several_col_2()\n", "df" ] }, { "cell_type": "code", "execution_count": 54, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 54, "metadata": {}, "output_type": "execute_result" } ], "source": [ "colors = ['#7cb5ec', '#434348', '#90ed7d', '#f7a35c', '#8085e9',\n", " '#f15c80', '#e4d354', '#2b908f', '#f45b5b', '#91e8e1']\n", "idx, col, data = hc.build.series_heatmap(df)\n", "\n", "g = hc.Highcharts()\n", "\n", "g.chart.type = 'heatmap'\n", "g.chart.width = 650\n", "g.chart.height = 450\n", "\n", "g.title.text = 'Sales per employee per weekday'\n", "\n", "g.xAxis.categories = idx\n", "g.yAxis.categories = col\n", "g.yAxis.title = ''\n", "\n", "\n", "g.colorAxis = {\n", " 'min': 0,\n", " 'minColor': '#FFFFFF',\n", " 'maxColor': colors[0],\n", "}\n", "\n", "g.legend = {\n", " 'align': 'right',\n", " 'layout': 'vertical',\n", " 'margin': 0,\n", " 'verticalAlign': 'top',\n", " 'y': 25,\n", " 'symbolHeight': 280 \n", "}\n", "\n", "g.tooltip = {\n", " 'formatter': \"\"\"function () {\n", " return '' + this.series.xAxis.categories[this.point.x] + ' sold
' +\n", " this.point.value + ' items on
' + this.series.yAxis.categories[this.point.y] + '';\n", " }\"\"\"\n", "}\n", "\n", "g.series = []\n", "g.series.append({\n", " 'name': 'Sales per Employee',\n", " 'borderWidth': 1,\n", " 'data': data,\n", " 'dataLabels': {\n", " 'enabled': True,\n", " 'color': '#000000',\n", " }\n", "})\n", "\n", "g.plot(version='6.1.2')\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "# Direct access to Highcharts/Highstock documentation\n", "+ Navigate the object property tree\n", "+ An `info()` method gives the official help\n", "+ WARNING: Once a property is set, the info method is not accessible any more" ] }, { "cell_type": "code", "execution_count": 55, "metadata": {}, "outputs": [], "source": [ "g = hc.Highcharts()" ] }, { "cell_type": "code", "execution_count": 56, "metadata": {}, "outputs": [ { "data": { "text/html": [ "

Documentation for 'yAxis'


  • Description
  • The Y axis or value axis. Normally this is the vertical axis, though if the \r\n", "\tchart is inverted this is the horizontal axis. In case of multiple axes, the yAxis\r\n", "\tnode is an array of configuration objects.

    \r\n", "\t

    See the Axis object for programmatic\r\n", "\taccess to the axis.



    " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

    Documentation for 'yAxis.labels.format'


  • Description
  • A format string for the axis label.

  • Demo
  • Add units to Y axis label
    " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "g.yAxis.info()\n", "g.yAxis.labels.format.info()" ] }, { "cell_type": "code", "execution_count": 57, "metadata": {}, "outputs": [], "source": [ "g = hc.Highstock()" ] }, { "cell_type": "code", "execution_count": 58, "metadata": {}, "outputs": [ { "data": { "text/html": [ "

    Documentation for 'plotOptions'


  • Description
  • The plotOptions is a wrapper object for config objects for each series type.\n", "\t\tThe config objects for each series can also be overridden for each series \n", "\t\titem as given in the series array.

    \n", "\t\t

    Configuration options for the series are given in three levels. Options\n", "\t\tfor all series in a chart are given in the plotOptions.series object. Then options for all series\n", "\t\tof a specific type are given in the plotOptions of that type, for example plotOptions.line.\n", "\t\tNext, options for one single series are given in the \n", "\t\tseries array.



    " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "g.plotOptions.info()" ] }, { "cell_type": "code", "execution_count": 59, "metadata": {}, "outputs": [], "source": [ "g = hc.Highcharts()" ] }, { "cell_type": "code", "execution_count": 60, "metadata": {}, "outputs": [ { "data": { "text/html": [ "

    Documentation for 'legend.align'


  • Description
  • The horizontal alignment of the legend box within the chart area. Valid values are \"left\", \"center\" and \"right\".

  • Demo
  • Legend at the right of the chart
    " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "g.legend.align.info()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "py37", "language": "python", "name": "py37" }, "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.7.10" } }, "nbformat": 4, "nbformat_minor": 1 }