繁体   English   中英

matplotlib不显示图形栏

[英]matplotlib not displaying the graph bars

我正在尝试使绘图显示在图形上,但是由于某种原因它什么也没显示。 我已经正确导入了matplotlib库,正在正确地从函数中获取值,并且当我将这些值传递给要在其中显示绘图的函数时,它将显示空白图像。 为了显示我得到的正确的值,我已经使用print和plotting命令打印了值,但不是打印图。这是代码。 我能够使用正确的情节

def GetCounts(data):
    return (data['Sex'].value_counts())

def Get_Plot(Points):
    _x1 = Points[0]
    _x2 = Points[1]
    _y = (_x1 + _x2) - 200
    print('male' + ' ' + str(_x1) + '\n','female' + ' '+ str(_x2), _y)
    plt.bar(height = _x1, tick_label = 'Male', left = _x1)
    plt.xlabel('Counts of people according to Sex')
    plt.ylabel('Number of people')
    plt.show()
Counts   = GetCounts(titanic)
Get_Plot(Counts)

我正在尝试在“男性”和“女性”中放置2个酒吧,但我不确定我将如何做到。 使用上面的代码,我只能放入其中之一。 请提前帮助谢谢。

您可能需要重新plt.barplt.bar文档

pyplot.bar(left, height, width=0.8, bottom=None, hold=None, data=None, **kwargs)
[...]
left :标量序列,条形图左侧的x坐标
height :标量或标量序列条的高度

因此,您可以将条形图放置在索引01 ,它们的高度将由Points给出

plt.bar(range(len(Points)),Points)
plt.xticks(range(len(Points)), Points.index)

暂无
暂无

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

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