如何解决使用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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。