matplotlib | set the maximum y-axis value in bar chart

Viewed 127

My output bar chart seems to default at just over 60% for my y-axis, without being told so.

As I am printing text above my bars themselves, I would like to manually increase the y-axis height.

Here is my attempt (indicated by comment):

# Data
    gc = ((sequence.count('G') + sequence.count('C')) / len(sequence)) * 100
    at = ((sequence.count('A') + sequence.count('T')) / len(sequence)) * 100

    # Plot
    plt.title(name + " Nitrogenous Base Pairs")
    plt.ylabel("Content as Percentage (%)")
    x = ["G-C Content", "A-T Content"]
    y = [gc, at]
    plt.yticks(np.arange(0, 75, 10)) # ATTEMPT
    plt.bar(x, y, color='blue')

    # Values
    for i, v in enumerate(y):
        plt.text(i, v, str(v) + "\n", ha='center', va='bottom')
        #plt.text(i, v, str(v))

    # Display & Save
    fig = plt.gcf()
    plt.draw()
    plt.show()
0 Answers
Related