Подтвердить что ты не робот

Настройки ширины графика в записной книжке ipython

У меня есть следующие графики:

sound signals

Было бы лучше, если бы они имели одинаковую ширину. Вы знаете, как это сделать в ipython-ноутбуке, когда я использую %matplotlib inline?

UPDATE:

Чтобы сгенерировать обе фигуры, я использую следующие функции:

import numpy as np
import matplotlib.pyplot as plt

def show_plots2d(title, plots, points, xlabel = '', ylabel = ''):
    """
    Shows 2D plot.

    Arguments:
        title : string
            Title of the plot.
        plots : array_like of pairs like array_like and array_like
            List of pairs,
            where first element is x axis and the second is the y axis.
        points : array_like of pairs like integer and integer
            List of pairs,
            where first element is x coordinate
            and the second is the y coordinate.
        xlabel : string
            Label of x axis
        ylabel : string
            Label of y axis
    """
    xv, yv = zip(*plots)
    y_exclNone = [y[y != np.array(None)] for y in yv]
    y_mins, y_maxs = zip(*
        [(float(min(y)), float(max(y))) for y in y_exclNone]
    )
    y_min = min(y_mins)
    y_max = max(y_maxs)
    y_amp = y_max - y_min
    plt.figure().suptitle(title)
    plt.axis(
        [xv[0][0], xv[0][-1], y_min - 0.3 * y_amp, y_max + 0.3 * y_amp]
    )
    plt.xlabel(xlabel)
    plt.ylabel(ylabel)
    for x, y in plots:
        plt.plot(x, y)
    for x, y in points:
        plt.plot(x, y, 'bo')
    plt.show()

def show_plot3d(title, x, y, z, xlabel = '', ylabel = '', zlabel = ''):
    """
    Shows 3D plot.

    Arguments:
        title : string
            Title of the plot.
        x : array_like
            List of x coordinates
        y : array_like
            List of y coordinates
        z : array_like
            List of z coordinates
        xlabel : string
            Label of x axis
        ylabel : string
            Label of y axis
        zlabel : string
            Label of z axis
    """
    plt.figure().suptitle(title)
    plt.pcolormesh(x, y, z)
    plt.axis([x[0], x[-1], y[0], y[-1]])
    plt.xlabel(xlabel)
    plt.ylabel(ylabel)
    plt.colorbar().set_label(zlabel)
    plt.show()
4b9b3361

Ответ 1

Если вы используете %pylab inline, вы можете (на новой строке) вставить следующую команду:

%pylab inline
pylab.rcParams['figure.figsize'] = (10, 6)

Это установит все фигуры в вашем документе (если не указано иное) размером (10, 6), где первая запись - ширина, а вторая - высота.

Подробнее см. в этом сообщении SO. fooobar.com/questions/66304/...

Ответ 2

Если вы не используете ноутбук ipython (например, OP), вы можете просто объявить размер, когда объявляете фигуру:

width = 12
height = 12
plt.figure(figsize=(width, height))

Ответ 3

Так я сделал это:

%matplotlib inline
import matplotlib.pyplot as plt
fig_size[0] = 12
fig_size[1] = 9
plt.rcParams["figure.figsize"] = fig_size

Вы можете определить свои собственные размеры.