减少两个箱形图之间的距离 [英] Reducing the distance between two boxplots

查看:383
本文介绍了减少两个箱形图之间的距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用python和matplotlib绘制下面显示的bloxplot. 有什么方法可以减小X轴上的两个箱形图之间的距离吗?

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):

推荐答案

尝试使用更改宽高比

ax.set_aspect(1.5) # or some other float

数字越大,该图应该越窄(越高):

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

一个圆圈将被拉伸,使得高度为宽度的num倍. aspect=1aspect=’equal’相同.

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

这篇关于减少两个箱形图之间的距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆