使用Plotly在量表中拨盘位置

问题描述

我正在跟踪一些在线示例,并尝试绘制仪表图,但不知道为什么刻度盘位置不正确。看来X是正确的,而Y是错误的。更改输入电平后,半径似乎正在更改。

代码如下:

import chart_studio.plotly as py
import plotly.graph_objs as go
from plotly.offline import iplot
import math


base_chart = {
    "values": [40,10,10],"labels": [" ","0","20","40","60","80","100"],"domain": {"x": [0,.48]},"marker": {
        "colors": [
            'rgb(255,255,255)','rgb(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,"VERY POOR","POOR","FAIR","GOOD","EXCELLENT"],"marker": {
        'colors': [
            'rgb(255,'rgb(232,226,202)','rgb(226,210,172)','rgb(223,189,139)',162,103)',126,64)'
        ]
    },0.48]},"hole": .3,"rotation": 90,"textposition": "inside","hoverinfo": "none"
}


x0 = 0.24
y0 = 0.5
r = 0.15
# Map my_raw_value to degrees. my_raw_value is between 0 and 100
raw_level_value = 20
theta = raw_level_value * 180 / 100
# and then into radians
theta = theta * math.pi / 180
x = x0 - r*math.cos(theta)
y = y0 + r*math.sin(theta)

path = 'M 0.235 0.5 L ' + str(x) + ' ' + str(y) + ' L 0.245 0.5 Z'



layout = {
    'xaxis': {
        'showticklabels': False,'showgrid': False,'zeroline': False,},'yaxis': {
        'showticklabels': False,'shapes': [
        {
            'type': 'path','path': path,#'M 0.235 0.5 L 0.29 0.64 L 0.245 0.5 Z',#
            'fillcolor': 'rgba(44,160,101,0.5)','line': {
                'width': 0.5
            },'xref': 'paper','yref': 'paper'
        }
    ],'annotations': [
        {
            'xref': 'paper','yref': 'paper','x': 0.22,'y': 0.45,'text': 'Level','showarrow': False
        }
    ]
}

# we don't want the boundary now
base_chart['marker']['line']['width'] = 0

fig = {"data": [base_chart,meter_chart],"layout": layout}
iplot(fig,filename='gauge-meter-chart')

这是raw_level_value = 20和raw_level_value = 50的输出。 raw_level_value = 20

raw_level_value = 50

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)