Change hatch density in barplot of Python Matplotlib.pyplot


The result is:

Change hatch density of barplot python matolotlib pyplot

This page shows how to increase the hatch density in barplot of matplotlib.
By changing the hatch string, you can change the hatch density.
In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
In [2]:
x = [1,2,3]
y = [1,2,3]
In [3]:
plt.figure(figsize=(7,5))
for i in range(6):
    # String to determine the type and density of the hatch.
    # For example, '///' is denser than '/'.
    hatch_str = "/"*i

    # Plot bars 
    ax = plt.subplot(2,3,i+1)
    ax.set_title(u"Hatch string is: %s"%hatch_str)
    bars = ax.bar(x,y,facecolor='cyan',edgecolor='black')
    
    # Set the hatch for each bar
    for bar in bars:
        bar.set_hatch(hatch_str)
    
plt.tight_layout()
plt.savefig('barplot_hatch_density.png',bbox_inches='tight',pad_inches=0.02,dpi=200)