正如您所注意到的,每个框绘制了 6 条线(因此您的p*6
索引)。
带索引的行p*6+4
具有盒子的宽度(即盒子内的中线)。所以我们可以用它来设置其他线的宽度。
您要更改的行有索引p*6+2
and p*6+3
.
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')
ax.lines[p*6+2].set_xdata(ax.lines[p*6+4].get_xdata())
ax.lines[p*6+3].set_xdata(ax.lines[p*6+4].get_xdata())
这也适用于具有多个框的示例:
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="whitegrid")
tips = sns.load_dataset("tips")
ax = sns.boxplot(x="day", y="total_bill", data=tips)
# 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')
ax.lines[p*6+2].set_xdata(ax.lines[p*6+4].get_xdata())
ax.lines[p*6+3].set_xdata(ax.lines[p*6+4].get_xdata())