Peter Chappy
Peter Chappy

Reputation: 1179

Changing the fontsize of a graph

I'm trying to change the fontsize of a graph, but it does not seem to be working.I see in the api that it has a property called fontsize, but it does not seem to be working.

 def generate_graph(d):
        data = format_fy(d)
        N = len(data[0])

        ind = np.arange(N)  # the x locations for the groups
        width = 0.2         # the width of the bars

        fig, ax = plt.subplots()

        #Configures the bars
        rects1 = ax.bar(ind, data[0], width, color='r')
        rects2 = ax.bar(ind+width, data[1], width, color='y')
        rects3 = ax.bar(ind+width*2, data[2], width, color='b')

        # adds Info to Graph
        ax.set_ylabel('$ Dollar Amounts')
        ax.set_title('Awarded Totals')
        #ax.set_xticks(ind+width)
        #ax.set_xticklabels(months, rotation='vertical')
        #ax.set_yticklabels(("25,000","50,000","75,000","100,000","125,000","150,000"))
        ax.legend((rects1[0], rects2[0], rects3), ('FY2012', 'FY2013', 'FY2014'), 2 )

        # Initialize the vertical-offset for the stacked bar chart.
        y_offset = np.array([0.0] * len(data[0]))

        # Plot bars and create text labels for the table
        cell_text = []
        for row in range(len(data)):
            y_offset = y_offset + data[row]
            cell_text.append(['%1.1f' % (x/1000.0) for x in y_offset])

        # Add a table at the bottom of the axes
        the_table = plt.table(cellText=cell_text,
                              rowLabels=('FY2012', 'FY2013', 'FY2014'),
                              colLabels=months,
                              fontsize=64,
                              loc='bottom')

        plt.subplots_adjust(left=0.1, bottom=0.15)

        plt.show()

Upvotes: 0

Views: 185

Answers (1)

Molly
Molly

Reputation: 13610

You can set the font size after you create the table with

the_table.set_fontsize(64)

You can also change the default font size for the entire figure with the rc settings.

import matplotlib as mpl

mpl.rcParams['font.size'] = 64

Upvotes: 1

Related Questions