I was trying to create a gauge to indicate percentage change. The onlly example I can find is this gauge here:
but I can’t get the needle to rotate. So instead, I use the color to indicate changes. Here is my mock up code:
from ipywidgets import FloatLogSlider, interact
@interact(ratio=FloatSlider(min=0, max=50, step=1, value=10))
def show_improve(ratio):
color_pair = ['rgb(232,206,202)','rgb(226,126,64)']
#if ratio>24:
# color_pair = color_pair[::-1]
base_chart = {
"values": [40, 10, 10, 10, 10, 10, 10],
"labels": ["-", "10", "8%", "6%", "4%", "2%", "0"],
"domain": {"x": [0, .48]},
"marker": {
"colors": [
'rgb(255, 255, 255)',
'rgb(255, 255, 255)',
'rgb(255, 255, 255)',
'rgb(255, 255, 255)',
'rgb(255, 255, 255)',
'rgb(255, 255, 255)',
'rgb(255, 255, 255)'
],
"line": {
"width": 1
}
},
"name": "Gauge",
"hole": .4,
"type": "pie",
"direction": "clockwise",
"rotation": 108,
"showlegend": False,
"hoverinfo": "none",
"textinfo": "label",
"textposition": "outside"
}
meter_chart = {
"values": [50, ratio, 0],
"marker": {
'colors': ['rgb(255, 255, 255)', *(color_pair[::-1])]
},
"domain": {"x": [0, 0.48]},
"name": "Gauge",
"hole": .3,
"type": "pie",
"direction": "counterclockwise",
"rotation": 90,
"showlegend": False,
"textinfo": "label",
"textposition": "none",
#"hoverinfo": "none"
}
layout = {
'xaxis': {
'showticklabels': False,
'showgrid': False,
'zeroline': False,
},
'yaxis': {
'showticklabels': False,
'showgrid': False,
'zeroline': False,
},
'annotations': [
{
'xref': 'paper',
'yref': 'paper',
'x': 0.23,
'y': 0.45,
'text': '{:.0%}'.format(ratio/50*0.1),
'showarrow': False
}
]
}
# we don't want the boundary now
base_chart['marker']['line']['width'] = 0
gauge_fig = {"data": [base_chart, meter_chart],
"layout": layout}
iplot(gauge_fig)
But I can’t get it to work for counter clockwise rotation. The main problem is when I switch the rotation to clock wise, the color is not the deep orange, but instead just white.
Any suggestion as to how I can do this?