我画了一个条形图,我希望每个条形都有一个学生名。 这是我的代码:
import matplotlib.pyplot
import numpy as np
names=["avi","jose","bob","nick","zelda","mark"]
pos=np.arange(6)+0.5
matplotlib.pyplot.bar(pos,(4,8,12,3,17,6),align="center",color="red")
matplotlib.pyplot.title("hight of students in unches",color="blue")
matplotlib.pyplot.xlabel("hight in inches",color="red")
matplotlib.pyplot.ylabel("students",color="red")
matplotlib.pyplot.tick_params(axis="x",color="white")
matplotlib.pyplot.tick_params(axis="y",color="white")
matplotlib.pyplot.yticks(pos,(names))
matplotlib.pyplot.show()
感谢您的帮助:)|
答案 0 :(得分:0)
从the docs中获取示例代码:
names=["avi","jose","bob","nick","zelda","mark"]
pos=np.arange(6)+0.5
bars = matplotlib.pyplot.bar(pos,(4,8,12,3,17,6),align="center",color="red")
matplotlib.pyplot.title("hight of students in unches",color="blue")
matplotlib.pyplot.xlabel("hight in inches",color="red")
matplotlib.pyplot.ylabel("students",color="red")
for i,bar in enumerate(bars):
matplotlib.pyplot.text(bar.get_x() + bar.get_width()/2., 1.05*bar.get_height(),
names[i],ha='center', va='bottom')
matplotlib.pyplot.tick_params(axis="x",color="white")
matplotlib.pyplot.tick_params(axis="y",color="white")
matplotlib.pyplot.show()