簡體   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