7

我正在制作一些非常大的图表,边框中的空白占用了大量像素,这些像素会更好地被数据使用。似乎边界随着图形的增长而增长。

这是我的图形代码的内容:

        import matplotlib
        from pylab import figure

        fig = figure()
        ax = fig.add_subplot(111)
        ax.plot_date((dates, dates), (highs, lows), '-', color='black')
        ax.plot_date(dates, closes, '-', marker='_', color='black')

        ax.set_title('Title')
        ax.grid(True)
        fig.set_figheight(96)
        fig.set_figwidth(24)

有没有办法减小边框的大小?也许某个地方的设置可以让我将边框保持在恒定的 2 英寸左右?

4

2 回答 2

6

由于看起来您只是在使用单个子图,因此您可能想跳过add_subplot并直接转到add_axes. 这将允许您给出轴的大小(在图形相对坐标中),因此您可以在图形中使其尽可能大。在您的情况下,这意味着您的代码看起来像

    import matplotlib.pyplot as plt

    fig = plt.figure()

    # add_axes takes [left, bottom, width, height]
    border_width = 0.05
    ax_size = [0+border_width, 0+border_width, 
               1-2*border_width, 1-2*border-width]
    ax = fig.add_axes(ax_size)
    ax.plot_date((dates, dates), (highs, lows), '-', color='black')
    ax.plot_date(dates, closes, '-', marker='_', color='black')

    ax.set_title('Title')
    ax.grid(True)
    fig.set_figheight(96)
    fig.set_figwidth(24)

如果您愿意,您甚至可以将参数直接放入set_figheight/调用中。set_figwidthfigure()

于 2009-07-30T16:23:51.007 回答
5

试用subplots_adjustAPI:

subplots_adjust(*args, **kwargs)

fig.subplots_adjust(left=None, bottom=None, right=None, wspace=None, hspace=None)

使用 kwargs 更新 SubplotParams(默认为 rc 其中 None )并更新子图位置

于 2009-07-30T06:45:10.777 回答