在破折号饼图中增加百分比的小数
Increasing decimal number of percentage in dash plotly pie chart
我正在尝试使用 dash 和 plotly 绘制饼图,但问题是当我绘制它时。
它将百分比四舍五入为 100%,因为它应该是 99.97%。
它显示 100%,但它必须显示类似 99.97% 的内容
dcc.Graph(
id="piechart_2",
figure={
"data": [
{
"labels": string_request,
"values": val_request,
"type": "pie",
"marker": {"line": {"color": "red", "width": 1}},
}
],
"layout": {
"height":500,
"width":500
},
'legend': {'x': 0, 'y': 1},
},
),
您可以创建自己的百分比,然后使用 textinfo
:
显示它们
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objects as go
labels = ['bind','rpz']
values = [99.9628, 0.0372]
text = [str(i)+'%' for i in values]
fig = go.Figure(data=[go.Pie(labels=labels,
values=values,
text=text,
textinfo='text')])
app = dash.Dash()
app.layout = html.Div([dcc.Graph(figure=fig)])
app.run_server(debug=True,
use_reloader=False)
你得到:
我正在尝试使用 dash 和 plotly 绘制饼图,但问题是当我绘制它时。 它将百分比四舍五入为 100%,因为它应该是 99.97%。
它显示 100%,但它必须显示类似 99.97% 的内容
dcc.Graph(
id="piechart_2",
figure={
"data": [
{
"labels": string_request,
"values": val_request,
"type": "pie",
"marker": {"line": {"color": "red", "width": 1}},
}
],
"layout": {
"height":500,
"width":500
},
'legend': {'x': 0, 'y': 1},
},
),
您可以创建自己的百分比,然后使用 textinfo
:
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objects as go
labels = ['bind','rpz']
values = [99.9628, 0.0372]
text = [str(i)+'%' for i in values]
fig = go.Figure(data=[go.Pie(labels=labels,
values=values,
text=text,
textinfo='text')])
app = dash.Dash()
app.layout = html.Div([dcc.Graph(figure=fig)])
app.run_server(debug=True,
use_reloader=False)
你得到: