Matplotlib BoxPlot X轴 [英] Matplotlib boxplot x axis

查看:296
本文介绍了Matplotlib BoxPlot X轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用数字问这个问题比较容易。目前,我使用matplotlib获取以下箱形图:



有没有一种方法来获取图形这样,但是每个框的位置都与相应的x轴数字一致(就像在常规散点图中一样,但是框而不是点)?



在在通过 labels = 自变量添加x轴上的数字的那一刻。

解决方案

您需要为



默认情况下,它使用值 [1、2,...,n] ,但是您可以为每个小节指定不同的x位置,xticks将为自动更新。


It's easier to ask this with a figure. At the moment i obtain the following boxplot graph using matplotlib:

Is there a way to obtain a figure like that, but with each box in a position coherent with the corresponding x-axis number (like in a normal scatter plot, but with boxes instead of points)?

At the moment the numbers on the x-axis are added by means of the labels= argument.

解决方案

You need to specify the positions argument to the boxplot constructor.

from matplotlib import pyplot as plt

plt.boxplot([[1,4],[2,5],[3,6]], positions=[2,4,5.5])

By default it uses the values [1, 2, ..., n] but you can specify a different x position for each bar and the xticks will be updated automatically.

这篇关于Matplotlib BoxPlot X轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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