更改颜色隐式p

2024-06-30 16:13:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下代码:

import sympy as syp


x, y = syp.symbols('x, y')


Equation_1 = - 2*x + y**2 - 5
Equation_2 = x**3 + syp.sin(y) - 10


syp.plot_implicit(syp.Or(syp.Eq(Equation_1, 0), syp.Eq(Equation_2, 0)), (x, -50, 50), (y, -50, 50))

它提供了以下图片:

enter image description here

你知道有什么方法可以用来改变第二条曲线的颜色吗?我认为这是不可能的,根据辛普森的documentation。在


Tags: or方法代码importplotas图片sin
2条回答

这是你的黑客,Sympy的Plot对象的.extend()方法

import sympy as syp
x, y = syp.symbols('x, y')

Eq0 = - 2*x + y**2 - 5
Eq1 = x**3 + syp.sin(y) - 10

p0 = syp.plot_implicit(Eq0, (x, -50, 50), (y, -50, 50), show=False)
p1 = syp.plot_implicit(Eq1, (x, -50, 50), (y, -50, 50), show=False, line_color='r')
p0.extend(p1)
p0.show()

enter image description here

似乎当前没有实现向plot_implicit函数传递任何类型的颜色参数。 不管您正在绘制多少函数,这都是正确的。 我怀疑可以添加这个功能,但目前还没有。在

另一方面,如果只打印直线,则可以执行此操作。 方法如下:

import sympy as sy
x = sy.symbols('x')
# Make two plots with different colors.
p1 = sy.plot(x**2, (x, -1, 1), show=False, line_color='b')
p2 = sy.plot(x**3, (x, -1, 1), show=False, line_color='r')
# Make the second one a part of the first one.
p1.extend(p2)
# Display the modified plot object.
p1.show()

A plot of two functions made using SymPy

相关问题 更多 >