【发布时间】:2019-09-14 23:42:44
【问题描述】:
我想在下面的箱线图中加宽胡须线。
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
data = pd.DataFrame({'Data': np.random.random(100), 'Type':['Category']*100})
fig, ax = plt.subplots()
# Plot boxplot setting the whiskers to the 5th and 95th percentiles
sns.boxplot(x='Type', y='Data', data=data, color = 'gray', whis = [5,95])
# Adjust boxplot and whisker line properties
for p, artist in enumerate(ax.artists):
artist.set_edgecolor('blue')
for q in range(p*6, p*6+6):
line = ax.lines[q]
line.set_color('pink')
我知道如何调整胡须颜色和线宽,但我无法弄清楚如何增加胡须的长度。我最接近的是尝试使用line.set_xdata([q/60-0.5, q/60+0.5]),但我得到了错误
ValueError: shape mismatch: objects cannot be broadcast to a single shape
理想情况下,我希望胡须百分位线与框的宽度相同。我该怎么做?
【问题讨论】:
标签: python-3.x matplotlib seaborn boxplot