Reputation: 3635
I'm using python 3.4.1, matplotlib 1.4, ipython 2.3 notebook, Arch Linux.
I'm trying to plot division of a plane by a line into two parts, for example two regions of classification, where one region has one value, and other region other value. I'm interested in region in interval [-1, 1]x[-1, 1].
Here is an example where everything works fine:
import numpy as np
import matplotlib.pyplot as plt
a, b = (2.5711100440212684, -0.87718711444141584)
x = np.arange(-1, 1, 0.001)
y1 = a*x + b
y2 = -1
y3 = 1
plt.fill_between(x, y1, y2, where=y1>y2, facecolor='green', interpolate=True)
plt.fill_between(x, y1, y3, where=y1<y3, facecolor='yellow', interpolate=True)
plt.axis([-1, 1, -1, 1])
This code gives me a picture as I think it should:
On the other hand, if I change a slope a bit, here's what I get:
import numpy as np
import matplotlib.pyplot as plt
a, b = (4.5711100440212684, -0.87718711444141584)
x = np.arange(-1, 1, 0.001)
y1 = a*x + b
y2 = -1
y3 = 1
plt.fill_between(x, y1, y2, where=y1>y2, facecolor='green', interpolate=True)
plt.fill_between(x, y1, y3, where=y1<y3, facecolor='yellow', interpolate=True)
plt.axis([-1, 1, -1, 1])
It's possible that I'm missing something. If anyone sees the mistake, please let me know.
EDIT: Oh yes, green filling seems to work for all values of slope well.
Upvotes: 1
Views: 485
Reputation: 2231
It works for me. Using Matplotlib nightly build, Ubuntu 14.04, Python 3.4, but running it from the console. Did you try that too?
Upvotes: 1