{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import plotly.plotly as py\n", "import plotly.tools as tls" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### The original graph" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "url = 'https://plot.ly/~vijayn/1212'\n", "tls.embed(url)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Grap the graph's figure object" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "vijay1212 = py.get_figure(url)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Set a custom range for yaxis2" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "{'autorange': True,\n", " 'overlaying': u'y',\n", " 'rangemode': u'tozero',\n", " 'showgrid': False,\n", " 'side': u'right',\n", " 'title': u'Take Rate %'}" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "vijay1212['layout']['yaxis2']" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [], "source": [ "vijay1212['layout']['yaxis2'].update(\n", " autorange=False, # must turn off autorange to make 'range' have an effect\n", " range=[0, 1.5]\n", ")" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "py.iplot(vijay1212, filename='for-vijay')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Prettify the xaxis\n", "\n", "Unfortunately Plotly date axes are not fully configurable yet. Setting `autotick` to `False` can lead to unwanted results in some situations." ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "{'autotick': False,\n", " 'tickfont': {'color': u'black', 'size': 10},\n", " 'ticks': u'outside'}" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "vijay1212['layout']['xaxis']" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": true }, "outputs": [], "source": [ "vijay1212['layout']['xaxis'].update(\n", " autotick=True\n", ")" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "py.iplot(vijay1212, filename='for-vijay-2')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The above graph isn't bad. But there is currently no easy way to tell plotly to show every month value in dates. Some alternatives include\n", "\n", "### Setting the axis type to `category`" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": true }, "outputs": [], "source": [ "vijay1212['layout']['xaxis'].update(\n", " type='category'\n", ")" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "py.iplot(vijay1212, validate=False, filename='for-vijay-3')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Setting custom tick values" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [], "source": [ "vijay1212['layout']['xaxis'].update(\n", " tickmode='array',\n", " tickvals=vijay1212['data'][0]['x'],\n", " ticktext=['Jan 2015', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', '' , '']\n", ")" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "py.iplot(vijay1212, validate=False, filename='for-vijay-4')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.6" } }, "nbformat": 4, "nbformat_minor": 0 }