在 python 中,我想绘制这个区域。
(1+x)*(1+y) >= 20
我不知道如何在 matplotlib
中做到这一点。我在 Internet 上搜索并找到了 fillplots
包,但我不明白如何将它用于两个变量。
这是填充图中的示例:
from fillplots import plot_regions
plotter = plot_regions([
[(lambda x: x ** 2,), # x ^ 2 > 0 and
(lambda x: x + 5,)], # x + 5 > 0
])
最佳答案
我没有足够的声誉来发表评论。我喜欢 Severin 的情节,但数学不正确。如果 y 为 -1,则该语句的计算结果为 0 且不能 >= 20。左下象限(和右上象限)是否应该有阴影,而不是中间?我认为这与 negative * negative 以及方程式的转换方式有关。
编辑:我尝试编辑 previous answer .我认为这接近要求的内容。垂直线是边界(实际上没有阴影),可以使用技术进行编辑 here .
from fillplots import plot_regions
plotter = plot_regions([
# positive y+1 values (require positive x+1)
# plotted in blue in this image
[(lambda x: 20.0/(1.0+x) - 1.0,), # False (default) means y > equation
(-1,) # and y > -1
],
# y < -1 returns a negative value for (y+1) and requires
# (x+1) to also have a negative value
# plotted in green in this image
[(lambda x: 20.0/(1.0+x) - 1.0, True), # True means y < equation
(-1, True) # and y < -1
],
], xlim=(-40,40), ylim=(-40, 40))
plt.show()
关于python - 如何绘制 (1+x)(1+y)>=20?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35532113/