这是我刚刚提出的问题的(更清晰的)转发,我的去身份化让人们感到困惑。
你好,我是使用 matplotlib.pyplot 在 python 中绘图的新手,并花了很多时间在这个网站和其他网站上搜索,并试图弄清楚这一点,但我还没有成功完成我想做的事情。
Using the code below, I have generated the following graph, which is a collection of courses and the percent of those enrolled who went on to complete the course:
What my code is creating:
然而,我想用 python 生成如下内容(用 MS Paint 粗略地制作,以向您传达我希望我的代码生成的所有内容):
What I want to create:
右侧轴标签是注册每门课程的人数,这是我希望提供的附加信息。另一种解决方案是将注册人数写在图表中,写在条形的末尾。但不管怎样,只要有效就可以了。
import matplotlib.pyplot as plt
y = ['Physics','Chemistry','Economics','Philosophy','Computer Science','Sociology','Biology','History','Overall']
x = [0.0,33.333333333333336,50.0,50.0,50.0,54.54545454545455,58.333333333333336,100.0,51.851851851851855]
alternativeYlabels = ['54', '1', '3', '12', '12', '2', '11', '12', '1']
plt.barh(y,x)
plt.title('Percent Completion Rate of Each Course')
plt.show()
如何更改代码以满足我的需求?另外,我怎样才能在我的图中添加与这里的每 20% 相对应的垂直网格线?
Thanks