Python Plotly format axis numbers as %(Python Plotly 将轴数格式化为 %)
本文介绍了Python Plotly 将轴数格式化为 %的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是数据框
df = pd.DataFrame({"col_1":[0.00143,0.00653,0.00732],"col_2":[0.00984,0.00192,0.00751]},index=['A','B','C'])
这是我的情节代码:
trace0 = go.Bar(
x=[df.columns[0],df.columns[1]],
y=[df.ix[0,0],df.ix[0,1]],
name=df.index[0],
# marker=dict(color=cof_pal[0]
)
trace1 = go.Bar(
x=[df.columns[0],df.columns[1]],
y=[df.ix[1,0],df.ix[1,1]],
name=df.index[1],
# marker=dict(color=cof_pal[1]
)
trace2 = go.Bar(
x=[df.columns[0],df.columns[1]],
y=[df.ix[2,0],df.ix[2,1]],
name=df.index[2],
# marker=dict(color=cof_pal[2]
)
layout = go.Layout(showlegend=True, title="VGl0bGU=", font=dict(size=Chart_Title_Font_Size),
yaxis=dict(title="UGVyY2VudGFnZSBDaGFuZ2UoJSk=", titlefont=dict(size=yaxis_font_size), tickfont=dict(size=yaxis_font_size)),
xaxis=dict(title="VGltZQ==", titlefont=dict(size=xaxis_font_size), tickfont=dict(size=yaxis_font_size))
)
data = [trace0,trace1,trace2]
fig = go.Figure(data=data, layout=layout)
iplot(fig, filename='fig1')
我需要 y 轴为 x.xx% 格式(或小数点后 n 位).
I need the y axis to be x.xx% format (or n digits after the decimal point).
另一个问题是:y轴标题百分比变化(%)"与y轴数字太接近了.如何进一步移动?
Another question is: the y axis title "Percentage Change(%)" is too close to the y axis numbers. How to move it further?
推荐答案
你可以设置 tickformat
在 layout
选项中.
You could set tickformat
in the layout
options.
import plotly.graph_objects as go
layout = go.Layout(yaxis=dict(tickformat=".2%"))
这篇关于Python Plotly 将轴数格式化为 %的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:Python Plotly 将轴数格式化为 %


猜你喜欢
- 我如何卸载 PyTorch? 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01