简体   繁体   English

fill_between填充不一致

[英]fill_between not filling consistently

I'm using python 3.4.1, matplotlib 1.4, ipython 2.3 notebook, Arch Linux. 我正在使用python 3.4.1,matplotlib 1.4,ipython 2.3笔记本,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]. 我对区间[-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. 编辑:哦,是的,绿色填充似乎对所有坡度值都适用。

It works for me. 这个对我有用。 Using Matplotlib nightly build, Ubuntu 14.04, Python 3.4, but running it from the console . 使用Matplotlib夜间构建,Ubuntu 14.04,Python 3.4, 但可以从控制台运行它 Did you try that too? 你也尝试过吗?

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM