pandas - boxplot median color settings issues

后端 未结 2 1066
醉话见心
醉话见心 2021-02-09 12:02

I\'m running Pandas 0.16.2 and Matplotlib 1.4.3. I have this issue coloring the median of the boxplot generated by the following code:

df = pd.DataFrame(np.rando         


        
2条回答
  •  暖寄归人
    2021-02-09 12:36

    Looking at the code for DataFrame.boxplot() there is some special code to handle the colors of the different elements that supersedes the kws passed to matplotlib's boxplot. In theory, there seem to be a way to pass a color= argument containing a dictionary with keys being 'boxes', 'whiskers', 'medians', 'caps' but I can't seem to get it to work when calling boxplot() directly.

    However, this seem to work:

    df.plot(kind='box', color={'medians': 'blue'}, 
            medianprops={'linestyle': '--', 'linewidth': 5})
    

    see Pandas Boxplot Examples

提交回复
热议问题