I am drawing a bloxplot shown below using python and matplotlib. Is there a way to reduce the distance between two drawers on the x axis?

This is the code I use 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 would like to get visually (although I wouldn’t mind if the boxes were a little closer to each other):

Filipe correia
source share