[英]matplotlib not displaying the graph bars
I'm trying to get the plot to show on a graph but it does not show anything for some reason. 我正在尝试使绘图显示在图形上,但是由于某种原因它什么也没显示。 I have properly imported the matplotlib library, I am properly getting the values from the function and when I pass those values to the function where I want the plot to be shown it displays blank image.
我已经正确导入了matplotlib库,正在正确地从函数中获取值,并且当我将这些值传递给要在其中显示绘图的函数时,它将显示空白图像。 To show that I am getting the correct values I have used print along with plotting commands the values are getting printed but not the plot Here's the code.
为了显示我得到的正确的值,我已经使用print和plotting命令打印了值,但不是打印图。这是代码。 I was able to get the plot correct using
我能够使用正确的情节
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)
I'm trying to get 2 bars placed in there 'Male' and 'Female' and I not sure how I will be able to. 我正在尝试在“男性”和“女性”中放置2个酒吧,但我不确定我将如何做到。 and with the code above I am only able to put only one of it.
使用上面的代码,我只能放入其中之一。 Please help thanks in advance.
请提前帮助谢谢。
You may want to revisit the plt.bar
documentation where it says 您可能需要重新
plt.bar
为plt.bar
文档
pyplot.bar(left, height, width=0.8, bottom=None, hold=None, data=None, **kwargs)
[...][...]
left
: sequence of scalars the x coordinates of the left sides of the barsleft
:标量序列,条形图左侧的x坐标
height
: scalar or sequence of scalars the height(s) of the barsheight
:标量或标量序列条的高度
You may thus position the bars at the indizes 0
and 1
and their height will be given by Points
因此,您可以将条形图放置在索引
0
和1
,它们的高度将由Points
给出
plt.bar(range(len(Points)),Points)
plt.xticks(range(len(Points)), Points.index)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.