2015-04-12 2 views
62

Ich habe folgende Plots bekam:Plot Breiteneinstellungen in ipython Notebook

sound signals

Es wäre schöner aussehen, wenn sie die gleiche Breite haben. Haben Sie eine Idee, wie es in Ipython Notebook zu tun, wenn ich %matplotlib inline verwende?

UPDATE:

beiden Zahlen generieren wir folgende Funktionen verwenden:

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

Können Sie uns ein kleines Beispiel für die Matplotlib geben, die Sie verwenden, nur der Vollständigkeit halber? –

+0

ok, komplett :) – pt12lol

Antwort

62

Wenn Sie %pylab inline verwenden, können Sie (auf eine neue Zeile) geben Sie den folgenden Befehl ein:

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

Dadurch werden alle Zahlen in Ihrem Dokument (sofern nicht anders angegeben) auf die Größegesetzt, wobei der erste Eintrag die Breite und der zweite die Höhe ist.

Weitere Informationen finden Sie in diesem Beitrag. https://stackoverflow.com/a/17231361/1419668

+8

einfach 'figsize (10, 6)' macht den Job und die Zeiten leichter zu merken. – Alleo

53

Wenn Sie nicht in einem ipython Notebook sind (wie die OP), können Sie auch nur die Größe erklären, wenn Sie die Zahl erklären:

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

Haben Sie eine Idee, in welchen Einheiten dies gemessen wird? –

+1

Einheiten sind Zoll, aber YMMV (die DPI Ihres Bildschirms stimmt möglicherweise nicht mit den Annahmen von matplotlib überein). Dies funktioniert auch nicht in der OP-Umgebung, einem iPython-Notebook! – hobs

+2

@hobs Welche Version von iPython Notebook laufen Sie? es funktioniert für mich in Jupyter. –

46

Dies ist so, wie ich es tat:

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

Sie können Ihre eigenen Größen definieren.

+6

plt.rcParams ["figure.figsize"] = [12, 9] # funktioniert – moritzschaefer

+0

'plt.rcParams [" figure.figsize "] = (12,9)' das funktioniert auch –