【发布时间】:2016-09-09 01:08:06
【问题描述】:
我正在尝试更改 Seaborn 箱线图中的箱体外观。我希望所有框都是透明的,并希望从列表中指定框边框。这是我正在使用的代码:
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
df = pd.DataFrame(np.random.rand(10,4),columns=list('ABCD'))
df['E'] = [1,2,3,1,1,4,3,2,3,1]
sns.boxplot(x=df['E'],y=df['C'])
# Plotting the legend outside the plot (above)
box = ax.get_position()
ax.set_position([box.x0, box.y0 + box.height * 0.1, box.width, box.height * 0.9])
handles, labels = ax.get_legend_handles_labels()
leg = plt.legend(handles[0:2], labels[0:2],
loc='upper center', bbox_to_anchor=(0.5, 1.10), ncol=2)
plt.show()
这个post 展示了如何改变一个盒子的颜色和盒子边缘颜色。但是,我想根据box_line_col = ['r','g',b','purple'] 之类的列表分配框边缘颜色。上面的代码在图中产生了 4 个框 - 我想从第一个(最左边)框开始分配自定义框边缘颜色,一直到最后一个(最右边)框。
是否可以从列表中指定框边缘颜色,同时保持框本身透明(facecolor = white)?
【问题讨论】:
-
This 回答我的类似问题可能会对您有所帮助。
标签: python-2.7 matplotlib seaborn