Plotly Python-绘图正值和负值与情节但错误的Yaxis

发布于 2025-02-08 10:02:04 字数 1614 浏览 1 评论 0原文

我想绘制公司的收入和净利润,但结果就像

”在此处输入图像描述”

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

enter image description here

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.

enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文