代码之家  ›  专栏  ›  技术社区  ›  serv-inc

plt。吧台离吧台太远了,怎么修复?

  •  0
  • serv-inc  · 技术社区  · 7 年前

    在里面 help(plt.bar) 在matplotlib版本2.0.0中,它表示条形图是

    [...] with rectangles bounded by:
    
      `left`, `left` + `width`, `bottom`, `bottom` + `height`
            (left, right, bottom and top edges)
    

    然而,电话 plt.bar(0, 1) 生产

    enter image description here

    不从开始 left == 0 ,但在 left - width/2 == -0.4 . 如何修复此问题?

    1 回复  |  直到 7 年前
        1
  •  1
  •   serv-inc    7 年前

    简短回答:

    plt.bar(0, 1, align="center")
    

    为什么?

    这个 documentation on github 表示要使用 align=edge :

    默认值为现在

    (x - width/2, x + width/2, bottom, bottom + height)
    

    [...] 这个 排列 仅关键字参数控件,如果 x个 已解释 作为矩形的中心或左边缘。[...]

    align : {'center', 'edge'}, optional, default: 'center'
        If 'center', interpret the *x* argument as the coordinates
        of the centers of the bars.  If 'edge', aligns bars by
        their left edges
        To align the bars on the right edge pass a negative
        *width* and ``align='edge'``