Plotly Python-绘图正值和负值与情节但错误的Yaxis
我想绘制公司的收入和净利润,但结果就像
yaxis很奇怪。Yaxis应在0和2017/6,2018/6的基本价值橙色条应不向上,y轴是随机顺序。
这是我的代码
def create_visual(filename):
createDir_if_not_exist('out/y')
createDir_if_not_exist('out/y/interactive')
print('read file: ' ,filename)
df = pd.read_csv('data/y/'+ filename)
stockcode = filename[0:5]
print('stockcode: ', stockcode)
#print(df['Total Turnover'])
#print(df['Net Profit'])
fig = make_subplots(specs=[[{"secondary_y": True}]])
fig.add_trace(go.Bar(name='Revenue', x=df['Closing Date'], y=df['Total Turnover'],base = 0,textposition='auto'))
fig.add_trace(go.Bar(name='Net Profit', x=df['Closing Date'], y=df['Net Profit'],base = 0,textposition='auto'))
fig.update_layout(barmode='group',template="seaborn",
title_text=str(df_stock[df_stock['StockCode'] == int(stockcode)]['Name of Securities'].values[0]) + ' ' + stockcode +'.HK',
xaxis_title="date",
title_font_color="red",
yaxis_title=df['Unit'].values[0] +' '+ df['Currency'].values[0],
font=dict(
size=18,
))
#fig.show()
pio.write_image(fig,'out/y/'+str(stockcode)+'.png', width=1480, height=780,format ='png')
fig.write_html('out/y/interactive/'+str(stockcode)+'.html')
I want to plot the revenue and the net profit of the company but the result is like this
The yaxis is strange.The yaxis should have base value at 0 and in 2017/6,2018/6 the orange bar should down not up, The y axis is random order.
This is my code
def create_visual(filename):
createDir_if_not_exist('out/y')
createDir_if_not_exist('out/y/interactive')
print('read file: ' ,filename)
df = pd.read_csv('data/y/'+ filename)
stockcode = filename[0:5]
print('stockcode: ', stockcode)
#print(df['Total Turnover'])
#print(df['Net Profit'])
fig = make_subplots(specs=[[{"secondary_y": True}]])
fig.add_trace(go.Bar(name='Revenue', x=df['Closing Date'], y=df['Total Turnover'],base = 0,textposition='auto'))
fig.add_trace(go.Bar(name='Net Profit', x=df['Closing Date'], y=df['Net Profit'],base = 0,textposition='auto'))
fig.update_layout(barmode='group',template="seaborn",
title_text=str(df_stock[df_stock['StockCode'] == int(stockcode)]['Name of Securities'].values[0]) + ' ' + stockcode +'.HK',
xaxis_title="date",
title_font_color="red",
yaxis_title=df['Unit'].values[0] +' '+ df['Currency'].values[0],
font=dict(
size=18,
))
#fig.show()
pio.write_image(fig,'out/y/'+str(stockcode)+'.png', width=1480, height=780,format ='png')
fig.write_html('out/y/interactive/'+str(stockcode)+'.html')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论