gpt4 book ai didi

python - 如何在plotly.express直方图中增加x刻度

转载 作者:行者123 更新时间:2023-12-04 07:38:19 25 4
gpt4 key购买 nike

我有一个带有代码的 Plotly 图:

import plotly.express as px
fig = px.histogram(df.col1, width= 1500, height= 700)
fig.show()
plotly 是这样的:
enter image description here
有没有办法可以将 x 刻度标记增加到每 2 或 5 个间隔?
尝试:
import plotly.express as px
fig = px.histogram(df.col1, width= 1500, height= 700)
fig.update_traces(xbins_size = 0.5)
fig.show()
并得到
enter image description here
问题是我想将 x 刻度增加到每 5 个以提高可见性,同时捕获 0-50 的范围。但间隔仍然是10。

最佳答案

fig.update_traces(xbins_size = <float>)

对于使用以下内容构建的图:
fig = px.histogram(x=np.random.randn(500))
enter image description here
您可以使用:
fig.update_traces(xbins_size = 0.5)
并得到:
enter image description here
现在,将其与:
fig.update_traces(xbins_size = 1)
这会给你:
enter image description here
完整代码:
import plotly.express as px
import numpy as np
np.random.seed(123)
fig = px.histogram(x=np.random.randn(500))
fig.update_traces(xbins_size = 0.5)
fig.show()

关于python - 如何在plotly.express直方图中增加x刻度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67631668/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com