有没有办法在 matplotlib 中制作多个水平箱线图? [英] Is there a way to make multiple horizontal boxplots in matplotlib?

查看:95
本文介绍了有没有办法在 matplotlib 中制作多个水平箱线图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个matplotlib图形,该图形将具有多个相互堆叠的水平箱形图.该文档展示了如何制作单个水平箱线图和如何制作多个垂直方向的线图在本节中.

I am trying to make a matplotlib figure that will have multiple horizontal boxplots stacked on one another. The documentation shows both how to make a single horizontal boxplot and how to make multiple vertically oriented plots in this section.

我尝试在以下代码中使用子图:

I tried using subplots as in the following code:

import numpy as np
import pylab as plt

totfigs = 5

plt.figure()
plt.hold = True

for i in np.arange(totfigs):    
    x = np.random.random(50)
    plt.subplot('{0}{1}{2}'.format(totfigs,1,i+1))
    plt.boxplot(x,vert=0)
plt.show()

我的输出结果只是一个水平的箱形图.

My output results in just a single horizontal boxplot though.

有人建议吗?

编辑:感谢@joaquin,我修复了plt.subplot 调用行.现在子图版本有效,但仍然希望所有的箱线图都在一个图中......

Edit: Thanks to @joaquin, I fixed the plt.subplot call line. Now the subplot version works, but still would like the boxplots all in one figure...

推荐答案

如果我对您的理解正确,则只需将包含要绘制的每个数组的列表(或2d数组)传递给boxplot.

If I'm understanding you correctly, you just need to pass boxplot a list (or a 2d array) containing each array you want to plot.

import numpy as np
import pylab as plt

totfigs = 5

plt.figure()
plt.hold = True
boxes=[]
for i in np.arange(totfigs):    
    x = np.random.random(50)
    boxes.append(x)

plt.boxplot(boxes,vert=0)
plt.show()

这篇关于有没有办法在 matplotlib 中制作多个水平箱线图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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