Python 如何降低matplotlib中的图案填充密度
我需要降低matplotlib制作的条中图案填充的密度。 添加图案填充的方式:Python 如何降低matplotlib中的图案填充密度,python,matplotlib,Python,Matplotlib,我需要降低matplotlib制作的条中图案填充的密度。 添加图案填充的方式: kwargs = {'hatch':'|'} rects2 = ax.bar(theta, day7, width,fill=False, align='edge', alpha=1, **kwargs) kwargs = {'hatch':'-'} rects1 = ax.bar(theta, day1, width,fill=False, align='edge', alpha=1, **kwargs) 我知
kwargs = {'hatch':'|'}
rects2 = ax.bar(theta, day7, width,fill=False, align='edge', alpha=1, **kwargs)
kwargs = {'hatch':'-'}
rects1 = ax.bar(theta, day1, width,fill=False, align='edge', alpha=1, **kwargs)
我知道你可以通过在图案中添加更多的字符来增加密度,但是你如何降低密度 这是一个完整的破解,但它应该适用于您的场景 基本上,可以定义一个新的填充图案,该填充图案的密度随着输入字符串的长度而降低。我已经为您修改了
HorizontalHatch
模式(注意下划线字符的使用):
然后必须将其添加到可用填充图案列表中:
matplotlib.hatch._hatch_types.append(CustomHorizontalHatch)
在打印代码中,现在可以使用定义的图案:
kwargs = {'hatch':'_'} # same as '-'
rects2 = ax.bar(theta, day7, width,fill=False, align='edge', alpha=1, **kwargs)
kwargs = {'hatch':'__'} # less dense version
rects1 = ax.bar(theta, day1, width,fill=False, align='edge', alpha=1, **kwargs)
请记住,这不是一个非常优雅的解决方案,在未来的版本中可能随时中断。此外,我的模式代码也是一个快速的黑客,您可能希望对其进行改进。我继承自
HorizontalHatch
,但是为了更大的灵活性,您可以在HatchPatternBase
的基础上进行构建,您可以在hatch中添加空格吗?
kwargs = {'hatch':'_'} # same as '-'
rects2 = ax.bar(theta, day7, width,fill=False, align='edge', alpha=1, **kwargs)
kwargs = {'hatch':'__'} # less dense version
rects1 = ax.bar(theta, day1, width,fill=False, align='edge', alpha=1, **kwargs)