更改图形的字体大小

时间:2014-08-19 18:38:31

标签: python matplotlib python-3.3

我正在尝试更改图形的字体大小,但它似乎没有工作。我在api中看到它有一个名为fontsize的属性,但它似乎没有用。

 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()

1 个答案:

答案 0 :(得分:1)

使用

创建表格后,您可以设置字体大小
the_table.set_fontsize(64)

您还可以使用rc settings更改整个数字的默认字体大小。

import matplotlib as mpl

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