python - Using pyplot to create grids of plots -


i new python , having difficulties plotting using pyplot. goal plot grid of plots in-line (%pylab inline) in juypter notebook.

i programmed function plot_cv plots cross-validation erorr on degree of polynomial of x across plots degree of penalization (lambda) supposed vary. there 10 elements in lambda , controlled first argument in plot_cv.

fig = plt.figure() ax1 = fig.add_subplot(1,1,1)  ax1 = plot_cv(1,cv_ve=cv_ve) 

gives

enter image description here

now think have use add_subplot create grid of plots in

fig = plt.figure() ax1 = fig.add_subplot(2,2,1) ax1 = plot_cv(1,cv_ve=cv_ve) ax2 = fig.add_subplot(2,2,2) ax2 = plot_cv(2,cv_ve=cv_ve) ax3 = fig.add_subplot(2,2,3) ax3 = plot_cv(3,cv_ve=cv_ve) ax4 = fig.add_subplot(2,2,4) ax4 = plot_cv(4,cv_ve=cv_ve) plt.show() 

enter image description here

if continue this, however, plots smaller , smaller , start overlap on x , y labels. here picture 3 3 plot.

enter image description here

is there way space plots evenly, not overlap , make better use of horizontal , vertical in-line space in jupyter notebook? illustrate point here screenshot jupyter:

enter image description here

final note: still need add title or annotation current level of lambda used in plot_cv.


edit: using tight layout suggested, gives:

enter image description here


edit 2: using fig.set_figheight , fig.set_figwidth use full length , heigth available.

enter image description here

a first suggestion problem taking @ "tight layout guide" matplotlib.

they have example looks visually similar situation. have examples , suggestions taking consideration axis labels , plot titles.

further more can control on figure size using figure matplotlib.figure class.

figure(figsize = (x,y))

figsize: x,y (inches)

edit:

here example pulled matplotlib website , added in the:

fig.set_figheight(15) fig.set_figwidth(15)

import matplotlib.pyplot plt  plt.rcparams['savefig.facecolor'] = "0.8"  def example_plot(ax, fontsize=12):      ax.plot([1, 2])      ax.locator_params(nbins=3)      ax.set_xlabel('x-label', fontsize=fontsize)      ax.set_ylabel('y-label', fontsize=fontsize)      ax.set_title('title', fontsize=fontsize)  plt.close('all') fig = plt.figure()  fig.set_figheight(15) fig.set_figwidth(15)   ax1 = plt.subplot2grid((3, 3), (0, 0)) ax2 = plt.subplot2grid((3, 3), (0, 1), colspan=2) ax3 = plt.subplot2grid((3, 3), (1, 0), colspan=2, rowspan=2) ax4 = plt.subplot2grid((3, 3), (1, 2), rowspan=2)  example_plot(ax1) example_plot(ax2) example_plot(ax3) example_plot(ax4)  plt.tight_layout() 

you can achieve padding of subplots using tight_layout way:

plt.tight_layout(pad=0.4, w_pad=0.5, h_pad=1.0)

that way can keep subplots crowding each other further.

have one!


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

sql - MySQL - Finding Empty relations -

linux - gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error is not recoverable: exiting now -