将plt.plot(x,y)与plt.boxplot()组合 [英] Combining plt.plot(x,y) with plt.boxplot()

查看:47
本文介绍了将plt.plot(x,y)与plt.boxplot()组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将普通 matplotlib.pyplot plt.plot(x,y) 与变量 y 作为变量 x 带有箱线图.但是,我只希望在 x 的某些(可变)位置上绘制箱线图,但这在matplotlib中似乎不起作用?

I'm trying to combine a normal matplotlib.pyplot plt.plot(x,y) with variable y as a function of variable x with a boxplot. However, I only want a boxplot on certain (variable) locations of x but this does not seem to work in matplotlib?

推荐答案

您想要这样的东西吗?positions kwarg to boxplot 允许您将箱线图放置在任意位置.

Are you wanting something like this? The positions kwarg to boxplot allows you to place the boxplots at arbitrary positions.

import matplotlib.pyplot as plt
import numpy as np

# Generate some data...
data = np.random.random((100, 5))
y = data.mean(axis=0)
x = np.random.random(y.size) * 10
x -= x.min()
x.sort()

# Plot a line between the means of each dataset
plt.plot(x, y, 'b-')

# Save the default tick positions, so we can reset them...
locs, labels = plt.xticks() 

plt.boxplot(data, positions=x, notch=True)

# Reset the xtick locations.
plt.xticks(locs)
plt.show()

这篇关于将plt.plot(x,y)与plt.boxplot()组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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