pandas - boxplot median color settings issues

后端 未结 2 1064
醉话见心
醉话见心 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:32

    Actually the following workaround works well, returning a dict from the boxplot command:

    df = pd.DataFrame(np.random.rand(10, 5), columns=['A', 'B', 'C', 'D', 'E'])
    
    fig, ax = plt.subplots()
    
    bp = df.boxplot(return_type='dict')
    

    and then assign directly colors and linewidth to the medians with:

    [[item.set_color('r') for item in bp[key]['medians']] for key in bp.keys()]
    [[item.set_linewidth(0.8) for item in bp[key]['medians']] for key in bp.keys()]
    

提交回复
热议问题