我试着把一个普通的matplotlib.pyplot plt.plot(x,y)和变量y结合起来,作为变量x的函数和一个盒子图。然而,我只想要在x的某些(变量)位置上的箱形图,但这似乎在matplotlib中不起作用?
发布于 2011-05-10 03:38:16
你想要这样的东西吗?boxplot的positions kwarg允许您将框图放置在任意位置。
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()

发布于 2021-05-23 20:32:10
这是对我有效的方法:
的x轴值
# Plot Box-plot
ax.boxplot(data, positions=x, notch=True)
# Get box-plot x-tick locations
locs=ax.get_xticks()
# Plot a line between the means of each dataset
# x-values = box-plot x-tick locations
# y-values = means
ax.plot(locs, y, 'b-')https://stackoverflow.com/questions/5938459
复制相似问题