I have written the following code which reads from another file I wrote (readscores.py) to find average ACT and SAT scores from every state and DC. The graph looks almost how I want it, but as you can see, the x labels are merged together and are unreadable. What is the best way to spread out these labels so that they don't squish together and still line up with their respective bars?
import matplotlib.pyplot as plt
import readscores
bar_width = .5
with open('actsat.txt', 'r') as input_file:
lines = input_file.readlines()
scores = readscores.read_scores(lines)
states = []
avg_act = []
avg_sat = []
lefts = [x for x in range(1, 52)]
for score in scores:
states.append(score['state'])
avg_act.append(float(score["act_average_score"]) / 36)
avg_sat.append((int(score["sat_average_math"]) + int(score["sat_average_reading"]) + int(score["sat_average_writing"])) / -2400)
plt.bar(left=lefts, height=avg_act, width=bar_width, bottom=0, color='lightblue', edgecolor='blue')
plt.bar(left=lefts, height=avg_sat, width=bar_width, bottom=0, color='grey', edgecolor='black')
plt.xlabel("State")
plt.ylabel("Score")
plt.xticks(range(52), [x for x in states])
plt.yticks([-1, -0.75, -0.5, -0.25, 0, 0.25, 0.5, 0.75, 1], [2400, 1800, 1200, 600, 0, 9, 18, 27, 36])
plt.show()