gpt4 book ai didi

python - Pylab 不存在高度为 0 的 "draw"条

转载 作者:太空宇宙 更新时间:2023-11-03 19:03:19 24 4
gpt4 key购买 nike

我正在尝试使用以下代码绘制条形图:

import pylab as p
first = ["2013-02-05", "2013-02-12", "2013-02-19", "2013-02-26", "2013-03-05", "2013-03-12"]

second = [0, 0, 0, 25, 35, 0]

fig = p.figure()
ax = fig.add_subplot(1,1,1)
N = len(second)
ind = range(N)
ax.bar(ind, second, facecolor='#777777', align='center', ecolor='black')
ax.set_xticklabels(first)
fig.autofmt_xdate()

结果在这里(抱歉,还不能发布图片):http://oi48.tinypic.com/vzxah3.jpg

如您所见,值为 0 的条被省略。我只想要那里的自由空间。

我做错了什么?

最佳答案

如何通过 numpy.clip() 将 0 更改为 0.0001?

import pylab as p
first = ["", "2013-02-05", "2013-02-12", "2013-02-19", "2013-02-26", "2013-03-05", "2013-03-12"]

second = [0.0, 0.0, 0, 25, 35, 0]

fig = p.figure()
ax = fig.add_subplot(1,1,1)
N = len(second)
ind = range(1, N+1)
ax.bar(ind, np.clip(second, 0.001, np.inf), facecolor='#777777', align='center', ecolor='black', )
ax.set_xticklabels(first)
fig.autofmt_xdate()

enter image description here

关于python - Pylab 不存在高度为 0 的 "draw"条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15497968/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com