Hatching an area between two defined functions in matplotlib

It's a little difficult for me. I would like to shade in the area where the black data points lie in the following figure (ignore histograms):

enter image description here

The two functions are as follows:

Solid black curve:

def log_OIII_Hb_OII(log_OII_Hb, eps=0):
    return eps + ((0.11)/(log_OII_Hb - eps -0.92)) + 0.85

      

Linear dotted line:

def LINERlog_OIII_Hb_OII(log_OII_Hb, eps=0):
    return 0.95*(log_OII_Hb)-0.4

      

I'm familiar with axScatter.fill_between

, but I'm not sure the best way to shade in the above region. Suggestions are very welcome. I've also defined some np.linspaces

for both functions, but I'm pretty sure the shadow can be accomplished with:

np.linspace(-0.5, 2.0).

      

+3


source to share


1 answer


You can use fill_between

for this. Here it is used to highlight the area between sin(a)

and cos(a)

:

enter image description here



code:

#!/usr/bin/python3

from numpy import *
from matplotlib import pyplot as plt

a = linspace(0, 6.28, 100)

x = sin(a)
y = cos(a)

fig = plt.figure()
ax = fig.add_subplot(111)

ax.plot(a, x, "k-", lw=3)
ax.plot(a, y, "k-", lw=3)

ax.fill_between(a, x, y, hatch = '///')

fig.savefig("mwe.png")

      

+1


source







All Articles