Python matplotlib.pylab 模块,subplots_adjust() 实例源码

我们从Python开源项目中,提取了以下12个代码示例,用于说明如何使用matplotlib.pylab.subplots_adjust()

项目:POT    作者:rflamary    | 项目源码 | 文件源码
def plot1D_mat(a, b, M, title=''):
    """ Plot matrix M  with the source and target 1D distribution

    Creates a subplot with the source distribution a on the left and
    target distribution b on the tot. The matrix M is shown in between.


    Parameters
    ----------
    a : np.array, shape (na,)
        Source distribution
    b : np.array, shape (nb,)
        Target distribution
    M : np.array, shape (na,nb)
        Matrix to plot
    """
    na, nb = M.shape

    gs = gridspec.GridSpec(3, 3)

    xa = np.arange(na)
    xb = np.arange(nb)

    ax1 = pl.subplot(gs[0, 1:])
    pl.plot(xb, b, 'r', label='Target distribution')
    pl.yticks(())
    pl.title(title)

    ax2 = pl.subplot(gs[1:, 0])
    pl.plot(a, xa, 'b', label='Source distribution')
    pl.gca().invert_xaxis()
    pl.gca().invert_yaxis()
    pl.xticks(())

    pl.subplot(gs[1:, 1:], sharex=ax1, sharey=ax2)
    pl.imshow(M, interpolation='nearest')
    pl.axis('off')

    pl.xlim((0, nb))
    pl.tight_layout()
    pl.subplots_adjust(wspace=0., hspace=0.2)
项目:hand_eye_calibration    作者:ethz-asl    | 项目源码 | 文件源码
def plot_angular_velocities(title,
                            angular_velocities,
                            angular_velocities_filtered,
                            block=True):
  fig = plt.figure()

  title_position = 1.05

  fig.suptitle(title, fontsize='24')

  a1 = plt.subplot(1, 2, 1)
  a1.set_title(
      "Angular Velocities Before Filtering \nvx [red], vy [green], vz [blue]",
      y=title_position)
  plt.plot(angular_velocities[:, 0], c='r')
  plt.plot(angular_velocities[:, 1], c='g')
  plt.plot(angular_velocities[:, 2], c='b')

  a2 = plt.subplot(1, 2, 2)
  a2.set_title(
      "Angular Velocities After Filtering \nvx [red], vy [green], vz [blue]", y=title_position)
  plt.plot(angular_velocities_filtered[:, 0], c='r')
  plt.plot(angular_velocities_filtered[:, 1], c='g')
  plt.plot(angular_velocities_filtered[:, 2], c='b')

  plt.subplots_adjust(left=0.025, right=0.975, top=0.8, bottom=0.05)

  if plt.get_backend() == 'TkAgg':
    mng = plt.get_current_fig_manager()
    max_size = mng.window.maxsize()
    max_size = (max_size[0], max_size[1] * 0.45)
    mng.resize(*max_size)
  plt.show(block=block)
项目:nmmn    作者:rsnemmen    | 项目源码 | 文件源码
def threehistsx(x1,x2,x3,x1leg='$x_1$',x2leg='$x_2$',x3leg='$x_3$',fig=1,fontsize=12,bins1=10,bins2=10,bins3=10):
    """
Script that pretty-plots three histograms of quantities x1, x2 and x3.

Arguments:
:param x1,x2,x3: arrays with data to be plotted
:param x1leg, x2leg, x3leg: legends for each histogram  
:param fig: which plot window should I use?

Example:
x1=Lbol(AD), x2=Lbol(JD), x3=Lbol(EHF10)

>>> threehists(x1,x2,x3,38,44,'AD','JD','EHF10','$\log L_{\\rm bol}$ (erg s$^{-1}$)')

Inspired by http://www.scipy.org/Cookbook/Matplotlib/Multiple_Subplots_with_One_Axis_Label.
    """
    pylab.rcParams.update({'font.size': fontsize})
    pylab.figure(fig)
    pylab.clf()

    pylab.subplot(3,1,1)
    pylab.hist(x1,label=x1leg,color='b',bins=bins1)
    pylab.legend(loc='best',frameon=False)

    pylab.subplot(3,1,2)
    pylab.hist(x2,label=x2leg,color='r',bins=bins2)
    pylab.legend(loc='best',frameon=False)

    pylab.subplot(3,1,3)
    pylab.hist(x3,label=x3leg,color='y',bins=bins3)
    pylab.legend(loc='best',frameon=False)

    pylab.minorticks_on()
    pylab.subplots_adjust(hspace=0.15)
    pylab.draw()
    pylab.show()
项目:bnpy    作者:bnpy    | 项目源码 | 文件源码
def show_top_words_over_time(
        task_output_path=None,
        vocabList=None,
        query_laps=[0, 1, 2, 5, None],
        ncols=10):
    '''
    '''
    nrows = len(query_laps)
    fig_handle, ax_handles_RC = pylab.subplots(
        figsize=(SMALL_FIG_SIZE[0] * ncols, SMALL_FIG_SIZE[1] * nrows),
        nrows=nrows, ncols=ncols, sharex=True, sharey=True)
    for row_id, lap_val in enumerate(query_laps):
        cur_model, lap_val = bnpy.load_model_at_lap(task_output_path, lap_val)
        # Plot the current model
        cur_ax_list = ax_handles_RC[row_id].flatten().tolist()
        bnpy.viz.PrintTopics.plotCompsFromHModel(
            cur_model,
            vocabList=vocabList,
            fontsize=9,
            Ktop=7,
            ax_list=cur_ax_list)
        cur_ax_list[0].set_ylabel("lap: %d" % lap_val)
    pylab.subplots_adjust(
        wspace=0.04, hspace=0.1, 
        left=0.01, right=0.99, top=0.99, bottom=0.1)
    pylab.tight_layout()


###############################################################################
#
# Show the topics over time
项目:bnpy    作者:bnpy    | 项目源码 | 文件源码
def show_top_words_over_time(
        task_output_path=None,
        vocabList=None,
        query_laps=[0, 1, 2, 5, None],
        ncols=10):
    '''
    '''
    nrows = len(query_laps)
    fig_handle, ax_handles_RC = pylab.subplots(
        figsize=(SMALL_FIG_SIZE[0] * ncols, SMALL_FIG_SIZE[1] * nrows),
        nrows=nrows, ncols=ncols, sharex=True, sharey=True)
    for row_id, lap_val in enumerate(query_laps):
        cur_model, lap_val = bnpy.load_model_at_lap(task_output_path, lap_val)
        # Plot the current model
        cur_ax_list = ax_handles_RC[row_id].flatten().tolist()
        bnpy.viz.PrintTopics.plotCompsFromHModel(
            cur_model,
            vocabList=vocabList,
            fontsize=9,
            Ktop=7,
            ax_list=cur_ax_list)
        cur_ax_list[0].set_ylabel("lap: %d" % lap_val)
    pylab.subplots_adjust(
        wspace=0.04, hspace=0.1, 
        left=0.01, right=0.99, top=0.99, bottom=0.1)
    pylab.tight_layout()


###############################################################################
#
# Show the topics over time
项目:bnpy    作者:bnpy    | 项目源码 | 文件源码
def show_top_words_over_time(
        task_output_path=None,
        vocabList=None,
        query_laps=[0, 1, 2, 5, None],
        ncols=10):
    '''
    '''
    nrows = len(query_laps)
    fig_handle, ax_handles_RC = pylab.subplots(
        figsize=(SMALL_FIG_SIZE[0] * ncols, SMALL_FIG_SIZE[1] * nrows),
        nrows=nrows, ncols=ncols, sharex=True, sharey=True)
    for row_id, lap_val in enumerate(query_laps):
        cur_model, lap_val = bnpy.load_model_at_lap(task_output_path, lap_val)
        # Plot the current model
        cur_ax_list = ax_handles_RC[row_id].flatten().tolist()
        bnpy.viz.PrintTopics.plotCompsFromHModel(
            cur_model,
            vocabList=vocabList,
            fontsize=9,
            Ktop=7,
            ax_list=cur_ax_list)
        cur_ax_list[0].set_ylabel("lap: %d" % lap_val)
    pylab.subplots_adjust(
        wspace=0.04, hspace=0.1, 
        left=0.01, right=0.99, top=0.99, bottom=0.1)
    pylab.tight_layout()


###############################################################################
#
# Show the topics over time
项目:bnpy    作者:bnpy    | 项目源码 | 文件源码
def _viz_Gauss_before_after(
        curModel=None, propModel=None,
        curSS=None, propSS=None,
        Plan=None,
        propLscore=None, curLscore=None,
        Data_b=None, Data_t=None, 
        **kwargs):
    pylab.subplots(
        nrows=1, ncols=2, figsize=(8, 4), num=1)
    h1 = pylab.subplot(1, 2, 1)
    h1.clear()
    GaussViz.plotGauss2DFromHModel(
        curModel, compsToHighlight=Plan['btargetCompID'], figH=h1)
    if curLscore is not None:
        pylab.title('%.4f' % (curLscore))

    h2 = pylab.subplot(1, 2, 2, sharex=h1, sharey=h1)
    h2.clear()
    newCompIDs = np.arange(curModel.obsModel.K, propModel.obsModel.K)
    GaussViz.plotGauss2DFromHModel(
        propModel, compsToHighlight=newCompIDs, figH=h2, Data=Data_t)
    if propLscore is not None:
        pylab.title('%.4f' % (propLscore))

        Lgain = propLscore - curLscore
        if Lgain > 0:
            pylab.xlabel('ACCEPT +%.2f' % (Lgain))
        else:
            pylab.xlabel('REJECT %.2f' % (Lgain))
    pylab.draw()
    pylab.subplots_adjust(hspace=0.1, top=0.9, bottom=0.15,
                          left=0.15, right=0.95)
项目:hand_eye_calibration    作者:ethz-asl    | 项目源码 | 文件源码
def plot_results(times_A, times_B, signal_A, signal_B,
                 convoluted_signals, time_offset, block=True):

  fig = plt.figure()

  title_position = 1.05

  matplotlib.rcParams.update({'font.size': 20})

  # fig.suptitle("Time Alignment", fontsize='24')
  a1 = plt.subplot(1, 3, 1)

  a1.get_xaxis().get_major_formatter().set_useOffset(False)

  plt.ylabel('angular velocity norm [rad]')
  plt.xlabel('time [s]')
  a1.set_title(
      "Before Time Alignment", y=title_position)
  plt.hold("on")

  min_time = min(np.amin(times_A), np.amin(times_B))
  times_A_zeroed = times_A - min_time
  times_B_zeroed = times_B - min_time

  plt.plot(times_A_zeroed, signal_A, c='r')
  plt.plot(times_B_zeroed, signal_B, c='b')

  times_A_shifted = times_A + time_offset

  a3 = plt.subplot(1, 3, 2)
  a3.get_xaxis().get_major_formatter().set_useOffset(False)
  plt.ylabel('correlation')
  plt.xlabel('sample idx offset')
  a3.set_title(
      "Correlation Result \n[Ideally has a single dominant peak.]",
      y=title_position)
  plt.hold("on")
  plt.plot(np.arange(-len(signal_A) + 1, len(signal_B)), convoluted_signals)

  a2 = plt.subplot(1, 3, 3)
  a2.get_xaxis().get_major_formatter().set_useOffset(False)
  plt.ylabel('angular velocity norm [rad]')
  plt.xlabel('time [s]')
  a2.set_title(
      "After Time Alignment", y=title_position)
  plt.hold("on")
  min_time = min(np.amin(times_A_shifted), np.amin(times_B))
  times_A_shifted_zeroed = times_A_shifted - min_time
  times_B_zeroed = times_B - min_time
  plt.plot(times_A_shifted_zeroed, signal_A, c='r')
  plt.plot(times_B_zeroed, signal_B, c='b')

  plt.subplots_adjust(left=0.04, right=0.99, top=0.8, bottom=0.15)

  if plt.get_backend() == 'TkAgg':
    mng = plt.get_current_fig_manager()
    max_size = mng.window.maxsize()
    max_size = (max_size[0], max_size[1] * 0.45)
    mng.resize(*max_size)
  plt.show(block=block)
项目:hand_eye_calibration    作者:ethz-asl    | 项目源码 | 文件源码
def plot_time_stamped_poses(title,
                            time_stamped_poses_A,
                            time_stamped_poses_B,
                            block=True):
  fig = plt.figure()

  title_position = 1.05

  fig.suptitle(title + " [A = top, B = bottom]", fontsize='24')

  a1 = plt.subplot(2, 2, 1)
  a1.set_title(
      "Orientation \nx [red], y [green], z [blue], w [cyan]",
      y=title_position)
  plt.plot(time_stamped_poses_A[:, 4], c='r')
  plt.plot(time_stamped_poses_A[:, 5], c='g')
  plt.plot(time_stamped_poses_A[:, 6], c='b')
  plt.plot(time_stamped_poses_A[:, 7], c='c')

  a2 = plt.subplot(2, 2, 2)
  a2.set_title(
      "Position (eye coordinate frame) \nx [red], y [green], z [blue]", y=title_position)
  plt.plot(time_stamped_poses_A[:, 1], c='r')
  plt.plot(time_stamped_poses_A[:, 2], c='g')
  plt.plot(time_stamped_poses_A[:, 3], c='b')

  a3 = plt.subplot(2, 2, 3)
  plt.plot(time_stamped_poses_B[:, 4], c='r')
  plt.plot(time_stamped_poses_B[:, 5], c='g')
  plt.plot(time_stamped_poses_B[:, 6], c='b')
  plt.plot(time_stamped_poses_B[:, 7], c='c')

  a4 = plt.subplot(2, 2, 4)
  plt.plot(time_stamped_poses_B[:, 1], c='r')
  plt.plot(time_stamped_poses_B[:, 2], c='g')
  plt.plot(time_stamped_poses_B[:, 3], c='b')

  plt.subplots_adjust(left=0.025, right=0.975, top=0.8, bottom=0.05)

  if plt.get_backend() == 'TkAgg':
    mng = plt.get_current_fig_manager()
    max_size = mng.window.maxsize()
    max_size = (max_size[0], max_size[1] * 0.45)
    mng.resize(*max_size)
  plt.show(block=block)
项目:nmmn    作者:rsnemmen    | 项目源码 | 文件源码
def twohists(x1,x2,xmin,xmax,range=None,x1leg='$x_1$',x2leg='$x_2$',xlabel='',fig=1,sharey=False,fontsize=12,bins1=10,bins2=10):
    """
Script that plots two histograms of quantities x1 and x2
sharing the same X-axis.

:param x1,x2: arrays with data to be plotted
:param xmin,xmax: lower and upper range of plotted values, will be used to set a consistent x-range
    for both histograms.
:param x1leg, x2leg: legends for each histogram 
:param xlabel: self-explanatory.
:param bins1,bins2: number of bins in each histogram
:param fig: which plot window should I use?
:param range: in the form (xmin,xmax), same as range argument for hist and applied to both
    histograms.

Inspired by `Scipy <http://www.scipy.org/Cookbook/Matplotlib/Multiple_Subplots_with_One_Axis_Label>`_.
    """

    pylab.rcParams.update({'font.size': fontsize})
    fig=pylab.figure(fig)
    pylab.clf()

    a=fig.add_subplot(2,1,1)
    if sharey==True:
        b=fig.add_subplot(2,1,2, sharex=a, sharey=a)
    else:
        b=fig.add_subplot(2,1,2, sharex=a)

    a.hist(x1,bins1,label=x1leg,color='b',histtype='stepfilled',range=range)
    a.legend(loc='best',frameon=False)
    a.set_xlim(xmin,xmax)

    b.hist(x2,bins2,label=x2leg,color='r',histtype='stepfilled',range=range)
    b.legend(loc='best',frameon=False)

    pylab.setp(a.get_xticklabels(), visible=False)

    b.set_xlabel(xlabel)
    b.set_ylabel('Number',verticalalignment='bottom')
    pylab.minorticks_on()
    pylab.subplots_adjust(hspace=0.15)
    pylab.draw()
    pylab.show()
项目:nmmn    作者:rsnemmen    | 项目源码 | 文件源码
def threehists(x1,x2,x3,xmin,xmax,x1leg='$x_1$',x2leg='$x_2$',x3leg='$x_3$',xlabel='',fig=1,sharey=False,fontsize=12):
    """
Script that plots three histograms of quantities x1, x2 and x3 
sharing the same X-axis.

Arguments:
- x1,x2,x3: arrays with data to be plotted
- xmin,xmax: lower and upper range of plotted values, will be used to set a consistent x-range for both histograms.
- x1leg, x2leg, x3leg: legends for each histogram   
- xlabel: self-explanatory.
- sharey: sharing the Y-axis among the histograms?
- fig: which plot window should I use?

Example:
x1=Lbol(AD), x2=Lbol(JD), x3=Lbol(EHF10)

>>> threehists(x1,x2,x3,38,44,'AD','JD','EHF10','$\log L_{\\rm bol}$ (erg s$^{-1}$)',sharey=True)

Inspired by `Scipy <http://www.scipy.org/Cookbook/Matplotlib/Multiple_Subplots_with_One_Axis_Label>`_.
    """
    pylab.rcParams.update({'font.size': fontsize})
    fig=pylab.figure(fig)
    pylab.clf()

    a=fig.add_subplot(3,1,1)
    if sharey==True:
        b=fig.add_subplot(3,1,2, sharex=a, sharey=a)
        c=fig.add_subplot(3,1,3, sharex=a, sharey=a)
    else:
        b=fig.add_subplot(3,1,2, sharex=a)
        c=fig.add_subplot(3,1,3, sharex=a)      

    a.hist(x1,label=x1leg,color='b',histtype='stepfilled')
    a.legend(loc='best',frameon=False)
    a.set_xlim(xmin,xmax)

    b.hist(x2,label=x2leg,color='r',histtype='stepfilled')
    b.legend(loc='best',frameon=False)

    c.hist(x3,label=x3leg,color='y',histtype='stepfilled')
    c.legend(loc='best',frameon=False)

    pylab.setp(a.get_xticklabels(), visible=False)
    pylab.setp(b.get_xticklabels(), visible=False)

    c.set_xlabel(xlabel)
    b.set_ylabel('Number')
    pylab.minorticks_on()
    pylab.subplots_adjust(hspace=0.15)
    pylab.draw()
    pylab.show()
项目:nmmn    作者:rsnemmen    | 项目源码 | 文件源码
def fourcumplot(x1,x2,x3,x4,xmin,xmax,x1leg='$x_1$',x2leg='$x_2$',x3leg='$x_3$',x4leg='$x_3$',xlabel='',ylabel='$N(x>x\')$',fig=1,sharey=False,fontsize=12,bins1=50,bins2=50,bins3=50,bins4=50):
    """
Script that plots the cumulative histograms of four variables x1, x2, x3 and x4
sharing the same X-axis. For each bin, Y is the fraction of the sample 
with values above X.

Arguments:

- x1,x2,x3,x4: arrays with data to be plotted
- xmin,xmax: lower and upper range of plotted values, will be used to set a consistent x-range
for both histograms.
- x1leg, x2leg, x3leg, x4leg: legends for each histogram    
- xlabel: self-explanatory.
- sharey: sharing the Y-axis among the histograms?
- bins1,bins2,...: number of bins in each histogram
- fig: which plot window should I use?

Inspired by `Scipy <http://www.scipy.org/Cookbook/Matplotlib/Multiple_Subplots_with_One_Axis_Label>`_.

v1 Jun. 2012: inherited from fourhists.
    """
    pylab.rcParams.update({'font.size': fontsize})
    fig=pylab.figure(fig)
    pylab.clf()

    a=fig.add_subplot(4,1,1)
    if sharey==True:
        b=fig.add_subplot(4,1,2, sharex=a, sharey=a)
        c=fig.add_subplot(4,1,3, sharex=a, sharey=a)
        d=fig.add_subplot(4,1,4, sharex=a, sharey=a)
    else:
        b=fig.add_subplot(4,1,2, sharex=a)
        c=fig.add_subplot(4,1,3, sharex=a)      
        d=fig.add_subplot(4,1,4, sharex=a)

    a.hist(x1,bins1,label=x1leg,color='b',cumulative=-True,normed=True,histtype='stepfilled')
    a.legend(loc='best',frameon=False)
    a.set_xlim(xmin,xmax)

    b.hist(x2,bins2,label=x2leg,color='r',cumulative=-True,normed=True,histtype='stepfilled')
    b.legend(loc='best',frameon=False)

    c.hist(x3,bins3,label=x3leg,color='y',cumulative=-True,normed=True,histtype='stepfilled')
    c.legend(loc='best',frameon=False)

    d.hist(x4,bins4,label=x4leg,color='g',cumulative=-True,normed=True,histtype='stepfilled')
    d.legend(loc='best',frameon=False)

    pylab.setp(a.get_xticklabels(), visible=False)
    pylab.setp(b.get_xticklabels(), visible=False)
    pylab.setp(c.get_xticklabels(), visible=False)

    d.set_xlabel(xlabel)
    c.set_ylabel(ylabel)
    pylab.minorticks_on()
    pylab.subplots_adjust(hspace=0.15)
    pylab.draw()
    pylab.show()