python - Matplotlib 方形箱线图

标签 python matplotlib boxplot

我在同一个图中有两个箱线图。出于样式原因,轴应该具有相同的长度,以便图形框是正方形的。我尝试使用 set_aspect 方法,但轴因范围而差异太大 结果很糟糕。

是否可以有 1:1 的轴,即使它们没有相同数量的点?

最佳答案

您可以使用 Axes.set_aspect如果将纵横比设置为轴限制的比率,则可以执行此操作。这是一个例子: alt text

from matplotlib.pyplot import figure, show

fig = figure()

ax0 = fig.add_subplot(1,2,1)
ax0.set_xlim(10., 10.5)
ax0.set_ylim(0, 100.)
ax0.set_aspect(.5/100)

ax1 = fig.add_subplot(1,2,2)
ax1.set_xlim(0., 1007)
ax1.set_ylim(0, 12.)
x0, x1 = ax1.get_xlim()
y0, y1 = ax1.get_ylim()
ax1.set_aspect((x1-x0)/(y1-y0))

show()

可能有更简单的方法,但我不知道。

关于python - Matplotlib 方形箱线图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1506647/

相关文章:

python - 关于使用 Python 启动 SSH 隧道的问题

python - 模块未找到错误 : No module named 'gevent.wsgi'

python - seetings.py 或 docker 中的数据库配置错误

python - 在堆积条形图中注释值 Matplotlib

python - Matplotlib - 同时在 3D 中绘制平面和点

python - 如何在 matplotlib 中绘制 5 组条形图?

具有均值和标准差的 R 手动箱线图 (ggplot2)

python - 为什么运行 SQLite(通过 python)会导致内存填满 "unofficially"?

r - ggplot2:强制为空的二级类别留出空间

python - Plotly:如何使用 go.box 而不是 px.box 对数据进行分组和指定颜色?