这是数据帧
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="Title", font=dict(size=Chart_Title_Font_Size), yaxis=dict(title='Percentage Change(%)', titlefont=dict(size=yaxis_font_size), tickfont=dict(size=yaxis_font_size)), xaxis=dict(title='Time', 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位数).
另一个问题是:y轴标题"百分比变化(%)"太靠近y轴数.如何进一步移动?
您可以tickformat
在layout
选项中进行设置.
layout = go.Layout(yaxis=dict(tickformat=".2%"))