python - imshow() subplots generate unwanted white spaces -


when plotting 2 (or more) subplots, there large areas of white spaces within plots (on 4 sides) seen here: enter image description here

following code used plot it.

from pylab import * matplotlib import rc, rcparams import matplotlib.pyplot plt  kk in range(57,58):     fn_i=str(kk)     image_file_1='redshiftoutput00'+fn_i+'_slice_z_radiopowerdsa.png'     image_file_2='redshiftoutput00'+fn_i+'_slice_z_radiopowertra.png'     image_file_3='redshiftoutput00'+fn_i+'_slice_z_radiopowerdsa+tra.png'      image_1 = plt.imread(image_file_1)     image_2 = plt.imread(image_file_2)     image_3 = plt.imread(image_file_3)            ax1 = subplot(131)     plt.imshow(image_1)     plt.axis('off')  # clear x- , y-axes      ax2 = subplot(132)     plt.imshow(image_2)     plt.axis('off')  # clear x- , y-axes      ax3 = subplot(133)     plt.imshow(image_3)     plt.axis('off')  # clear x- , y-axes      plt.savefig('redshiftoutput00'+fn_i+'_all.png') 

i uploading 3 images used in code making code minimal working example

1) https://drive.google.com/file/d/0b6l5irwtubhwstf2r3e1thbgevk/view?usp=sharing

2) https://drive.google.com/file/d/0b6l5irwtubhwafi4dhazcwpioeu/view?usp=sharing

3) https://drive.google.com/file/d/0b6l5irwtubhwag8xclflcgjnauk/view?usp=sharing

how can remove white space ? tried fixing whole plot size, still white space comming.

mel's comment above (use plt.tight_layout()) works in many situations, need little more control. manipulate axes more finely (useful, e.g., when have lots of colorbars or twin-ned axes), can use plt.subplots_adjust() or gridspec object.

gridspec objects allow specify horizontal , vertical extents of individual axes, proportional width , height & spacing. subplots_adjust() moves axes around after you've plotted stuff on them. prefer using first option, both documented well.

it may fool around size of figure. if have lots of whitespace width-wise, make width of figure smaller.

here's example code used set recent plot:

gs = gridspec.gridspec(         nrows=1, ncols=3, left=0.1, bottom=0.25, right=0.95, top=0.95,         wspace=0.05, hspace=0., width_ratios=[1, 1, 1]) nii_ax = plt.subplot(gs[0]) sii_ax = plt.subplot(gs[1]) oi_ax = plt.subplot(gs[2]) 

and result:

gridspec result

then, if need colorbar, adjust right argument in gridspec 0.85, , use fig.add_axes() list [left_lim, bottom, width, height] , use axis argument fig.colorbar()


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -