gpt4 book ai didi

python - 结合 plt.plot(x,y) 与 plt.boxplot()

转载 作者:太空狗 更新时间:2023-10-29 17:15:55 27 4
gpt4 key购买 nike

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

最佳答案

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

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

enter image description here

关于python - 结合 plt.plot(x,y) 与 plt.boxplot(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5938459/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com