import matplotlib.pyplot as plt
import education
list_of_record = education.get_all_states()
virginia_education = education.get_state('Virginia')
attendance = virginia_education["attendance"]
if "attendance" in virginia_education:
student_rate = attendance ["average student rate"]
teacher_rate = attendance ["average teacher rate"]
rates = [student_rate, teacher_rate]
x = rates
plt.bar (1,student_rate)
plt.bar (2,teacher_rate)
plt.title ('Average Student Rate Attendence vs. Average Teacher Rate Attendence in Virginia')
plt.show ()
我希望将x轴标记为“学生费率”和“教师费率”。我知道如何标记x轴,但我不知道如何更改1,1.2,1.2等。
plt.bar (1,student_rate)
plt.bar (2,teacher_rate)
我该怎么做才能解决这个问题?
答案 0 :(得分:0)
根据matplotlib网站: http://matplotlib.org/examples/ticks_and_spines/ticklabels_demo_rotation.html
你可以创建一个标签数组:
labels = ["student rate", "teacher rate"]
然后修改x刻度:
plt.xticks(x, labels)