用袖扣绘制轴问题

2024-06-11 16:23:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图避免在一个由袖扣生成的堆积条形图中y轴上的死角

数据如下:

    delay_percentage
crane_delay_type_gkey   1.0      2.0      3.0        4.0         5.0       6.0  7.0 8.0 9.0 10.0    ... 18.0     19.0   20.0    21.0    22.0    23.0    24.0    25.0    26.0    27.0
  crane_gkey                                                                                    
         288     76.425626  1.846134    0.000000    0.701747    0.000000     0.000000   4.933820    0.939261    0.000000    0.000000    ... 1.338717     0.291495   0.421048    0.269903    0.151145    0.636970    6.395612    1.589187    0.000000    0.172738
         333    46.153846   0.000000    0.000000    0.000000    0.000000    0.000000    7.692308    0.000000    0.000000    0.000000    ... 0.000000    0.000000    0.000000    0.000000    0.000000    0.000000    0.000000    0.000000    0.000000    0.000000
         338    81.818182   0.000000    0.000000    0.000000    0.000000    0.000000    0.000000    0.000000    0.000000    0.000000    ... 0.000000    0.000000    0.000000    0.000000    0.000000    0.000000    0.000000    0.000000    0.000000    0.000000
         345    75.000000   0.000000    0.000000    0.000000    0.000000    0.000000    0.000000    12.500000   0.000000    0.000000    ... 0.000000    0.000000    0.000000    0.000000    0.000000    0.000000    0.000000    0.000000    0.000000    0.000000

我用来做袖扣的代码:

^{pr2}$

情节如下:

enter image description here

我怎样去掉横栏之间的空隙?尤其是y轴值288和333之间的巨大差距。在

我试过把crane_gkey值[y轴值]变成一个字符串,它没有做任何事情。 另外,我将如何增加袖扣条形图中的条的厚度。在


Tags: 数据代码type条形图delay情节percentagecrane
1条回答
网友
1楼 · 发布于 2024-06-11 16:23:27

为什么不在源代码处切断空值呢。我是说,使用pandas本身。在

下面是我的方法。在

我们有一个示例数据帧。在

df = pd.DataFrame({"A": ["foo", "foo", "foo", "foo", "foo",
                          "bar", "bar", "bar", "bar"],
                    "B": ["one", "one", "one", "two", "two",
                          "one", "one", "two", "two"],
                    "C": ["small", "large", "large", "small",
                          "small", "large", "small", "small",
                          "large"],
                    "D": [1, 2, 2, 0, 0, 4, 5, 6, 7]})

在枢轴上给我的。在

^{pr2}$

参考号:here

输出:

C       large   small
A   B       
bar one 4.0     5.0
    two 7.0     6.0
foo one 4.0     1.0
    two NaN     0.0

所以如果我们去掉foo and two我们就能得到正确的图。我用的是这个。在

table = table.fillna(0) # replace all NaN values to zero
table = table[(table.T != 0).any()] # remove all the rows which are having sum as zero.

输出:

C       large   small
A   B       
bar one 4.0     5.0
    two 7.0     6.0
foo one 4.0     1.0

最后我们可以用袖扣

plot = table.iplot(kind ='barh', barmode = 'stack', asFigure=True)
py_offline.iplot(plot)

请尝试这个解决方案,让我知道如果这解决了你的问题!在

相关问题 更多 >