I want to fill the space between two point on x-axis
The code I tried is as follows
import matplotlib.pyplot as plt
import pandas as pd
data = pd.read_csv('data.csv')
plt.figure(figsize=(15, 7))
plt.plot(data.x, data.y)
plt.fill_betweenx(y=data.y, x1 = 600, x2 = 1200, alpha = 0.5, color = 'green')
plt.show()
and I cannot figure out what is the problem here, please help
CodePudding user response:
Here is a working example:
import matplotlib.pyplot as plt
import pandas as pd
plt.figure(figsize=(15, 7))
plt.plot([0, 1], [2, 3])
plt.fill_betweenx(y=[2.5, 2.9], x1 = .2, x2 = .4, alpha = 0.5, color = 'green')
plt.show()
Since your example is not reproducible I can't help more.
Maybe replace y=data.y
by y=[data.y.min(), y=data.y.max()]
?
CodePudding user response:
import random as rd
import matplotlib.pylab as plt
l = [rd.randint(1,100) for i in range(1000)]
plt.figure(figsize=(15, 7))
plt.plot(l)
plt.fill_betweenx(y=[min(l), max(l)], x1 = 200, x2 = 400, alpha = 0.5, color = 'green')