You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: How to make guage meter charts in Python with Plotly.
16
26
display_as: basic
@@ -24,124 +34,86 @@ jupyter:
24
34
permalink: python/gauge-charts/
25
35
thumbnail: thumbnail/gauge.jpg
26
36
title: Python Gauge Chart | plotly
37
+
v4upgrade: true
27
38
---
28
39
29
-
#### New to Plotly?
30
-
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/).
31
-
<br>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).
32
-
<br>We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started!
33
-
34
-
35
-
##### Gauge Chart Outline
40
+
#### Gauge Chart Outline
36
41
37
42
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).
38
43
39
44
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.
40
45
41
46
42
-
#####Base Chart (rotated)
47
+
#### Base Chart (rotated)
43
48
44
49
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.
You can see that the first section's value is equal to the sum of other sections.<br>
124
105
We are using `rotation` and `direction` parameters to start the sections from 3 o'clock `[rotation=90]` instead of the default value of 12 o'clock `[rotation=0]`.
125
106
126
107
127
-
After imposing on the base chart, it'll look like this.
128
-
129
-
130
-
<div>
131
-
<a href="https://plot.ly/~pravj648/235/" target="_blank" title="Gauge vs Gauge" style="display: block; text-align: center;"><img src="https://plot.ly/~pravj648/235.png" alt="Gauge vs Gauge" style="max-width: 100%;width: 600px;" width="600" onerror="this.onerror=null;this.src='https://plot.ly/404.png';" /></a>
Now we need a `dial` to show the current position in the meter at a particular time.<br>
139
111
`Plotly's`[path shape](https://plot.ly/python/reference/#layout-shapes-path) can be used for this. A nice explanation of SVG path is available [here](https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths) by Mozilla.<br>
140
112
We can use a `filled triangle` to create our `Dial`.
141
113
142
114
143
-
```python
144
-
...
115
+
116
+
```
145
117
'shapes': [
146
118
{
147
119
'type': 'path',
@@ -154,80 +126,89 @@ We can use a `filled triangle` to create our `Dial`.
154
126
'yref': 'paper'
155
127
}
156
128
]
157
-
...
158
129
```
159
130
160
131
132
+
161
133
For the `filled-triangle`, the first point `(0.235, 0.5)` is left to the center of meter `(0.24, 0.5)`, the second point `(0.24 0.62)` is representing the current position on the `semi-circle` and the third point `(0.245, 0.5)` is just right to the center.
162
134
163
135
164
136
`M` represents the `'Move'` command that moves cursor to a particular point, `L` is the `'Line To'` command and `Z` represents the `'Close Path'` command. This way, this path string makes a triangle with those three points.
0 commit comments