【问题标题】:How to make my Plotly Express line graph to start with 0? [duplicate]如何使我的 Plotly Express 折线图以 0 开头? [复制]
【发布时间】:2021-11-14 21:39:20
【问题描述】:

我已经制作了一个 Plotly Express 折线图:

fig = px.line(pmt_old_and_new, x="day", y="value", color="type")


fig.show()

但是它在图表上没有 0 作为起点。如何添加它?我希望轴有 0

【问题讨论】:

    标签: python python-3.x plot plotly plotly-express


    【解决方案1】:

    定义轴的范围:

    import numpy as np
    import pandas as pd
    import plotly.express as px
    
    df = pd.concat([pd.DataFrame({"day":range(50),"avg_spending":np.random.randint(1,17,50)}).assign(type=type) for type in ["one","two"]])
    
    fig = px.line(df, x="day", y="avg_spending", color="type")
    fig.update_layout(yaxis={"dtick":1,"range":[0,17]},margin={"t":0,"b":0},height=500)
    
    
    

    【讨论】:

      猜你喜欢
      • 2020-04-24
      • 1970-01-01
      • 1970-01-01
      • 2021-01-29
      • 1970-01-01
      • 1970-01-01
      • 2014-07-08
      • 1970-01-01
      • 2022-01-13
      相关资源
      最近更新 更多