18

箱ひげ図の変数の関数として、通常のmatplotlib.pyplotplt.plot(x,y)と変数を組み合わせようとしています。ただし、の特定の(変数)場所にのみ箱ひげ図が必要ですが、これはmatplotlibでは機能しないようです?yxx

4

2 に答える 2

27

このようなものが欲しいですか?positionskwarg 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()

ここに画像の説明を入力してください

于 2011-05-09T19:38:15.863 に答える
0

これは私のために働いたものです:

  1. プロットボックス-プロット
  2. boxt-plotのx軸の目盛りの位置を取得します
  3. 箱ひげ図のx軸の目盛りの位置を折れ線グラフの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-')


于 2021-05-23T12:32:09.533 に答える