首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >ipython notebook中的绘图宽度设置

ipython notebook中的绘图宽度设置
EN

Stack Overflow用户
提问于 2015-04-12 19:48:46
回答 3查看 127.6K关注 0票数 84

我得到了以下图:

如果它们有相同的宽度会看起来更好。你知道当我使用%matplotlib inline时如何在ipython notebook中做吗?

更新:

为了生成这两个图形,我使用以下函数:

代码语言:javascript
复制
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()
EN

回答 3

Stack Overflow用户

发布于 2015-04-14 02:48:02

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

代码语言:javascript
复制
%pylab inline
pylab.rcParams['figure.figsize'] = (10, 6)

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

请看这篇文章,了解更多细节。https://stackoverflow.com/a/17231361/1419668

票数 81
EN

Stack Overflow用户

发布于 2016-08-15 23:30:49

我是这样做的:

代码语言:javascript
复制
%matplotlib inline
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = (12, 9) # (w, h)

您可以定义自己的尺寸。

票数 69
EN

Stack Overflow用户

发布于 2016-01-14 18:46:17

如果您不在ipython笔记本中(如OP),您也可以在声明图形时只声明大小:

代码语言:javascript
复制
width = 12
height = 12
plt.figure(figsize=(width, height))
票数 66
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29589119

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档