0
x軸に均等にボックスプロットを広げたいと思います。次のコードは、2つのボックスプロットがどちら側にもたくさんのスペースがある図形を生成します。 generateでは、boxplotsの数にかかわらず、boxplotsを均等に広げたい(この例では2つだけですが、一般的にはたくさんあります)。Boxplotsが均等に広がっています
import matplotlib.pyplot as plt
statistic_dict = {0.40000000000000002: [0.36003616645322273, 0.40526649416305677, 0.46522159350924536], 0.20000000000000001: [0.11932912803730165, 0.23235825966896217, 0.12380728472472625]}
def draw_boxplot(y_values, x_values, edge_color, fill_color):
bp = plt.boxplot(y_values, patch_artist=True, positions=x_values)
for element in ['boxes', 'whiskers', 'fliers', 'medians', 'caps']:
plt.setp(bp[element], color=edge_color)
plt.xlabel("x label ")
plt.ylabel("y label ")
plt.title("Title")
for patch in bp['boxes']:
patch.set(facecolor=fill_color)
y_values = statistic_dict.values()
x_values = statistic_dict.keys()
draw_boxplot(y_values, x_values, "skyblue", "white")
plt.savefig('fileName.png', bbox_inches='tight')
plt.close()
plt.gca()。autoscale()works! plt.gca()。margin(x = 0.2)がエラーを生成します。ValueError:2つ以上の引数が指定されました – user58925
これは、古いバージョンのmatplotlibを使用しているためです。私は古いバージョンのための有効な解決策を与えることはできません。 – ImportanceOfBeingErnest