{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### New to Plotly?\n",
"Plotly's Python library is free and open source! [Get started](https://plot.ly/python/getting-started/) by downloading the client and [reading the primer](https://plot.ly/python/getting-started/).\n",
"
You can set up Plotly to work in [online](https://plot.ly/python/getting-started/#initialization-for-online-plotting) or [offline](https://plot.ly/python/getting-started/#initialization-for-offline-plotting) mode, or in [jupyter notebooks](https://plot.ly/python/getting-started/#start-plotting-online).\n",
"
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Gauge Chart Outline\n",
"\n",
"We will use `donut` charts with custom colors to create a `semi-circular` gauge meter, such that lower half of the chart is invisible(same color as background).\n",
"\n",
"This `semi-circular` meter will be overlapped on a base `donut` chart to create the `analog range` of the meter. We will have to rotate the base chart to align the range marks in the edges of meter's section, because by default `Plotly` places them at the center of a pie section."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Base Chart (rotated)\n",
"\n",
"To make a `gauge meter` with 5 equally sized sections, we will create 6 sections in the base chart. So that center(position of label) aligns with the edges of each section."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import plotly.plotly as py\n",
"import plotly.graph_objs as go\n",
"\n",
"base_chart = {\n",
" \"values\": [40, 10, 10, 10, 10, 10, 10],\n",
" \"labels\": [\"-\", \"0\", \"20\", \"40\", \"60\", \"80\", \"100\"],\n",
" \"domain\": {\"x\": [0, .48]},\n",
" \"marker\": {\n",
" \"colors\": [\n",
" 'rgb(255, 255, 255)',\n",
" 'rgb(255, 255, 255)',\n",
" 'rgb(255, 255, 255)',\n",
" 'rgb(255, 255, 255)',\n",
" 'rgb(255, 255, 255)',\n",
" 'rgb(255, 255, 255)',\n",
" 'rgb(255, 255, 255)'\n",
" ],\n",
" \"line\": {\n",
" \"width\": 1\n",
" }\n",
" },\n",
" \"name\": \"Gauge\",\n",
" \"hole\": .4,\n",
" \"type\": \"pie\",\n",
" \"direction\": \"clockwise\",\n",
" \"rotation\": 108,\n",
" \"showlegend\": False,\n",
" \"hoverinfo\": \"none\",\n",
" \"textinfo\": \"label\",\n",
" \"textposition\": \"outside\"\n",
"}\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Outline of the generated `base chart` will look like the one below."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"