Note
Go to the endto download the full example code.
Hatchcolor Demo#
The color of the hatch can be set using thehatchcolor parameter. The followingexamples show how to use thehatchcolor parameter to set the color of the hatchinPatch andCollection.
See alsoHatch demo for more usage examplesof hatching.
Patch Hatchcolor#
This example shows how to use thehatchcolor parameter to set the color ofthe hatch in a rectangle and a bar plot. Thehatchcolor parameter is available forPatch, child classes of Patch, and methods that pass through to Patch.
importmatplotlib.pyplotaspltimportnumpyasnpimportmatplotlib.cmascmfrommatplotlib.patchesimportRectanglefig,(ax1,ax2)=plt.subplots(1,2)# Rectangle with red hatch color and black edge colorax1.add_patch(Rectangle((0.1,0.5),0.8,0.3,hatch=".",hatchcolor='red',edgecolor='black',lw=2))# If hatchcolor is not passed, the hatch will match the edge colorax1.add_patch(Rectangle((0.1,0.1),0.8,0.3,hatch='x',edgecolor='orange',lw=2))x=np.arange(1,5)y=np.arange(1,5)ax2.bar(x,y,facecolor='none',edgecolor='red',hatch='//',hatchcolor='blue')ax2.set_xlim(0,5)ax2.set_ylim(0,5)

Collection Hatchcolor#
The following example shows how to use thehatchcolor parameter to set the color ofthe hatch in a scatter plot. Thehatchcolor parameter can also be passed toCollection, child classes of Collection, and methods that passthrough to Collection.
fig,ax=plt.subplots()num_points_x=10num_points_y=9x=np.linspace(0,1,num_points_x)y=np.linspace(0,1,num_points_y)X,Y=np.meshgrid(x,y)X[1::2,:]+=(x[1]-x[0])/2# stagger every alternate row# As ax.scatter (PathCollection) is drawn row by row, setting hatchcolors to the# first row is enough, as the colors will be cycled through for the next rows.colors=[cm.rainbow(val)forvalinx]ax.scatter(X.ravel(),Y.ravel(),s=1700,facecolor="none",edgecolor="gray",linewidth=2,marker="h",# Use hexagon as markerhatch="xxx",hatchcolor=colors,)ax.set_xlim(0,1)ax.set_ylim(0,1)plt.show()

References
The use of the following functions, methods, classes and modules is shownin this example:
Total running time of the script: (0 minutes 1.670 seconds)