[英]How do I make a horizontal histogram in Plotly express using Python?
I'm trying to make a horizontal histogram with my data but I'm getting this error:我正在尝试用我的数据制作水平直方图,但出现此错误:
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
I always get a beautiful histogram when I use当我使用时,我总是得到一个漂亮的直方图
px.histogram(df, x="columnName")
But the moment I try to change it to horizontal, it doesn't work.但是当我尝试将其更改为水平时,它不起作用。
px.histogram(df, y="columnName") or px.histogram(df, x="columnName", orientation='h') don't work.
I have no data with NoneType and I even tried px.histogram(y=np.random.randn(500))
but it still doesn't work.我没有使用 NoneType 的数据,我什至尝试过
px.histogram(y=np.random.randn(500))
但它仍然不起作用。
I tried using go.Figure(data=[go.Histogram(y=df['columnName'])])
which does give me a horizontal hist but then I'm unable to change the colors according to a different column.我尝试使用
go.Figure(data=[go.Histogram(y=df['columnName'])])
确实给了我一个水平的历史,但是我无法根据不同的列更改 colors。
Any help would be appreciated, thanks in advance:)任何帮助将不胜感激,在此先感谢:)
If you take a look at the details below, you'll see that I fully agree that this is a little strange.如果你看看下面的细节,你会发现我完全同意这有点奇怪。 But if you'd like to determine the orientation, just leave out the
orientation
parameter and swith between assigning the values to x
and y
.但是,如果您想确定方向,只需省略
orientation
参数并在将值分配给x
和y
之间切换。
fig = px.histogram(x=np.random.randn(500))
fig = px.histogram(y=np.random.randn(500))
This whole thing seems a bit strange.这整件事似乎有点奇怪。
orientation
is listed as a parameter for px.histogram
and should take either 'h'
or 'v'
as valid arguments. orientation
被列为px.histogram
的参数,并且应该将'h'
或'v'
作为有效的 arguments。
orientation: str, one of
'h'
for horizontal or'v'
for vertical.方向:str,水平方向的
'h'
或垂直方向'v'
之一。 (default'v'
ifx
andy
are provided and both continous or both categorical, otherwise'v'
('h'
) ifx
(y
) is categorical andy
(x
) is continuous, otherwise'v'
('h'
) if onlyx
(y
) is(如果提供了
x
和y
并且都是连续的或都是分类的,则默认为'v'
,否则,如果x
(y
) 是分类的并且y
(x
) 是连续的,则为 'v'v'
(''h'
'),否则为'v'
('h'
) 如果只有x
(y
) 是
But I'm getting this error:但我收到了这个错误:
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
类型错误:+ 不支持的操作数类型:“NoneType”和“str”
In any case, px.histogram(x=np.random.randn(500))
produces the following horizontal plot plot:在任何情况下,
px.histogram(x=np.random.randn(500))
产生以下水平 plot plot:
If you'd like to flip it to vertical, just exchange x with y
:如果您想将其翻转为垂直,只需将
x with y
交换:
px.histogram(y=np.random.randn(500))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.