I want to have multiple contourf plots with different hatch features in the same figure.
from matplotlib import pyplot as plt
import matplotlib.colors as mcolors
import numpy as np
x=np.arange(0,10,0.1)
y=np.arange(0,10,0.1)
xx, yy = np.meshgrid(x, y)
Z=np.where(xx>yy, 1, 0)
hatch_color=mcolors.to_rgba("green")
plt.rcParams['hatch.linewidth'] = 2
plt.rcParams['hatch.color'] = hatch_color
plt.contourf(xx, yy, Z,levels=[0.5, 1],hatches=["\"],colors='red')
plt.show()
plt.clf()
Z=np.where(xx<yy, 1, 0)
hatch_color=mcolors.to_rgba("blue")
plt.rcParams['hatch.linewidth'] = 10
plt.rcParams['hatch.color'] = hatch_color
plt.contourf(xx, yy, Z,levels=[0.5, 1],hatches=["\"],colors='red')
plt.show()
plt.clf()
The code above produces two plots
firstplot
second plot
I used plt.rcParams to set the hatch properties like color or linewidth. However these changes are global and concern all the hetches in the figure.
I would like to produce these two contourf plots with different hetches in one figure. How can I achieve that? I expect that one can change the hatch properties locally instead of using plt.rcParams , but I can’t figure out how.
Paweł Korzeb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.