编辑:FWIW 我正在 Illustrator 中修复图例,但更喜欢自动完成,因为我有大约 20 个这样的图要制作
我遵循这个非常有用的答案,将自定义图例添加到 matplotlib violinplot,它不支持自己的图例。除了当我尝试添加舱口时,它效果很好。
这是我的标签代码(我尝试以两种不同的方式添加补丁):
labels = [ 'Low entropy bin', 'Medium entropy bin', 'High entropy bin' ]
legend_patches = 3*[matplotlib.patches.Patch( color='#DCDCDC', hatch='//' )]
for i in legend_patches:
i.set_hatch( '//' )
Run Code Online (Sandbox Code Playgroud)
孵化小提琴本身的代码运行良好:
parts = plt.violinplot( data, showmeans=False, showextrema=True, showmedians=True )
hatch_dict = { 0:'', 1:'///', 2:'xx' }
for t in range(0, 3):
third = range( 0, len( labels ) )[ t*(int(len(labels)/3)):(((t+1)*int(len(labels)/3))) ]
for i in third:
face = parts['bodies'][i]
face.set_hatch( hatch_dict[t] )
Run Code Online (Sandbox Code Playgroud)
与垃圾箱相关的数据(未显示)已经针对其他类别进行了颜色编码,因此我真的很想在不同的舱口中显示垃圾箱。