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

标签 python plotly

我有一个带有代码的 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/

相关文章:

python - 检测列中两个连续的空值

python - 构建 conda 包 : The package must be rebuilt with conda-build > 2. 0

python - 按键对字典项目进行排序,超越字母数字排序

python - 如何在条形图中连续显示累计计数(x轴没有空格)

python - Tensorflow per_process_gpu_memory_fraction 不工作

python - Plotly:如何使用折线图的下拉列表更新绘图数据?

python - 如何在plotly中绘制venn3

r - 在 R 中绘制 ellipse3d?

python - 如何设置y轴的范围

python - Pandas :如果下一列的行包含特定值,则将列数据除以数字