Reducing the distance between two boxplots

matplotlib

Solution

Try changing the aspect ratio using

ax.set_aspect(1.5) # or some other float

The larger then number, the narrower (and taller) the plot should be:

a circle will be stretched such that the height is `num` times the width. `aspect=1` is the same as `aspect=’equal’`.

http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes.set_aspect

Problem

I'm drawing the bloxplot shown below using python and matplotlib. Is there any way I can reduce the distance between the two boxplots on the X axis? This is the code that I'm using to get the figure above: ``` import matplotlib.pyplot as plt from matplotlib import rcParams rcParams['ytick.direction'] = 'out' rcParams['xtick.direction'] = 'out' fig = plt.figure() xlabels = ["CG", "EG"] ax = fig.add_subplot(111) ax.boxplot([values_cg, values_eg]) ax.set_xticks(np.arange(len(xlabels))+1) ax.set_xticklabels(xlabels, rotation=45, ha='right') fig.subplots_adjust(bottom=0.3) ylabels = yticks = np.linspace(0, 20, 5) ax.set_yticks(yticks) ax.set_yticklabels(ylabels) ax.tick_params(axis='x', pad=10) ax.tick_params(axis='y', pad=10) plt.savefig(os.path.join(output_dir, "output.pdf")) ``` And this is an example closer to what I'd like to get visually (although I wouldn't mind if the boxplots were even a bit closer to each other):

Original source