python - ipython笔记本中的绘图宽度设置

标签 python matplotlib jupyter-notebook ipython

我有以下情节:

sound signals

如果它们具有相同的宽度会更好看。当我使用 %matplotlib inline 时,您知道如何在 ipython notebook 中执行此操作吗?

更新:

要生成两个数字,我使用以下函数:

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

最佳答案

如果您使用 %pylab inline,您可以(在新行上)插入以下命令:

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

这会将文档中的所有图形(除非另有说明)设置为 (10, 6) 的大小,其中第一个条目是宽度,第二个是高度。

有关详细信息,请参阅此 SO 帖子。 https://stackoverflow.com/a/17231361/1419668

关于python - ipython笔记本中的绘图宽度设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29589119/

相关文章:

python - matplotlib 5 方形子图

python - Wheel 是对另一个 Python 的引用

python - 如何在Python中分割一个巨大的文本数据集?

python - Windows 上的 Heroku Django 应用程序开发

python - 如何以粗线绘制指定数据

通过 pip 安装 Python GDAL 失败

python - matplotlib 给定范围内的等高线图

knitr - Jupyter 中的 R-markdown .Rmd 或 knitr markdown

python - 关于 plotly 离线和更新 jupyter 笔记本中的图表的困惑