简体   繁体   English

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

[英]How to increase x ticks in plotly.express histogram

I have a Plotly graph with code:我有一个带有代码的 Plotly 图:

import plotly.express as px
fig = px.histogram(df.col1, width= 1500, height= 700)
fig.show()

and the plot looks like this: plot 看起来像这样: 在此处输入图像描述

Is there a way I can increase the x tick markings to every 2 or 5 interval?有没有办法可以将 x 刻度标记增加到每 2 或 5 个间隔?

Tried:试过:

import plotly.express as px
fig = px.histogram(df.col1, width= 1500, height= 700)
fig.update_traces(xbins_size = 0.5)
fig.show()

and got并得到在此处输入图像描述

The issue is that I would like to increase x ticks to every 5 to improve visibility while capturing the range of 0-50.问题是我想将 x 刻度增加到每 5 次以提高可见性,同时捕获 0-50 的范围。 But the interval is still 10.但是间隔仍然是10。

fig.update_traces(xbins_size = <float>)

For a plot built with:对于使用以下组件构建的 plot:

fig = px.histogram(x=np.random.randn(500))

在此处输入图像描述

You can use:您可以使用:

fig.update_traces(xbins_size = 0.5)

And get:并得到:

在此处输入图像描述

Now, compare this with:现在,将其与以下内容进行比较:

fig.update_traces(xbins_size = 1)

Which will give you:这会给你:

在此处输入图像描述

Complete code:完整代码:

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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM