绘制来自小数点的百分比
我有一个要在列图中绘制的数据框。数据帧显示了小数点的百分比(例如0.994400),我想在我的图表上显示它们为99.944%。
我试图多次更改图表的轴,但是值总是汇总到100%。如何获得轴和悬停数字以显示小数点?
例如,第一个数据点应显示99.944%,但显示100%。
我的dataframe:df_uptime_percentage
名称 | 百分比 |
---|---|
API 1 | 0.9994400 |
API 2 | API |
0.999913 | API |
4 | 0.999925 |
API 5 | 0.9999461 |
0.999914
cf.go_offline()
fig = df_uptime_percentage.iplot(kind='bar',
yTitle='Percent Uptime',
xTitle='API Endpoint',
asFigure = True)
fig.update_layout(yaxis_tickformat = '%')
fig.update_layout(hovermode="x unified")
fig.iplot()
我导入的库:
import time
from dateutil.relativedelta import relativedelta
import math
import requests
import re
import json
import pandas as pd
import cufflinks as cf
from plotly.offline import download_plotlyjs, init_notebook_mode, iplot
from plotly.graph_objs import *
init_notebook_mode()
%matplotlib inline
I have a dataframe that I want to plot in a column chart. The dataframe shows percentages in decimal points (such as 0.9994400) and I would like to show them on my chart as 99.944%.
I've tried to change the axis of the chart multiple times, but the values always round up to 100%. How can I get the axis and hover numbers to show the decimal points?
For example, the first data point should show 99.944%, but it shows 100%.
My dataframe: df_uptime_percentage
Name | Percentage |
---|---|
API 1 | 0.9994400 |
API 2 | 0.999914 |
API 3 | 0.999913 |
API 4 | 0.999925 |
API 5 | 0.999461 |
My plot script:
cf.go_offline()
fig = df_uptime_percentage.iplot(kind='bar',
yTitle='Percent Uptime',
xTitle='API Endpoint',
asFigure = True)
fig.update_layout(yaxis_tickformat = '%')
fig.update_layout(hovermode="x unified")
fig.iplot()
My imported libraries:
import time
from dateutil.relativedelta import relativedelta
import math
import requests
import re
import json
import pandas as pd
import cufflinks as cf
from plotly.offline import download_plotlyjs, init_notebook_mode, iplot
from plotly.graph_objs import *
init_notebook_mode()
%matplotlib inline
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定是什么原因导致数字被四舍五入,但是如果您在百分比表中添加Y轴刻度标记并添加数字数,则轴将有两个小数点,并且悬停文本也将有两个十进制位置。
I am not sure what is causing the numbers to be rounded, but if you add the y-axis tick marks to the percent table and add the number of digits, the axis will have two decimal places, and the hover text will also have two decimal places.
您并没有完全捕捉到代码中的位置,您从数据框架中导入数字以用于图,但是从您描述问题的方式来看,我认为这与浮点数错误有关。我编写了一些基本代码来转换您获得的API1的值:
此代码打印
99.94
。如果要将代码中的第三行更改为99.944
。希望这有帮助!
Didn't quite catch where in your code you imported the numbers from your data frame to be used for your plot, but from how you describe your issue, I'm thinking this has something to do with a floating-point error. I wrote some basic code to convert the value you got for API1:
This code prints
99.94
. If you were to change the 3rd line in the code toit would give you
99.944
.Hope this helps!