0

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?Here is the graph currently drawn by the graph.

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()
  • 1
    Sounds a bit like asking how to put more letters on a paper. The answer is: (a) use a bigger paper or (b) use smaller letters. So for (a) you can use `plt.figure(figsize=(width,height))` where width, height are in inch. For (b) there are a [lot of different answers](http://stackoverflow.com/questions/6390393/matplotlib-make-tick-labels-font-size-smaller), just pick one that you like. Rotating the labels may also help recude their size. – ImportanceOfBeingErnest Nov 21 '16 at 15:45
  • That did it. I wasn't aware of that function. Thanks. – nalydttirrem Nov 21 '16 at 15:56

0 Answers0