我试图在 SymPy 中绘制函数 x^2 的图,并想用 x=3、y=9 的线覆盖它,然后还围绕某些点绘制一个圆圈。我已经用代码完成了上述所有操作
import sympy as sp
x = sp.Symbol('x')
# first plot the function
sp.plotting.plot_parametric( (x, x**2, (x,0,4)),
# then the straight lines
(3, x, (x,0,16)), (x, 9, (x,0,4)),
# then the circle
(.1*sp.cos(x)+3.1, .1*sp.sin(x)+(3.1**2), (x,0,6.5)) )
Run Code Online (Sandbox Code Playgroud)
然而,所有的曲线都是蓝色的,我想让每条曲线都有不同的颜色。查看文档并没有告诉我当我有几条曲线时如何做到这一点,只有当我有一条曲线时,而且我line_color='red'在几个地方玩弄扔东西并没有让我到任何地方。任何人都知道适当的方法或好的黑客?
你已经绘制了三个函数,因此你有三个图,以通常的方式编号。您可以通过以下方式单独修改它们的所谓美学。不要阅读关于这一点的文档,它说line_color应该是一个返回浮点数的函数。如果你这样做,你可能会像我刚刚在一个黑洞中所做的那样花一个小时。
>>> from sympy import *
>>> var('x')
>>> aPlot = plotting.plot_parametric( (x, x**2, (x,0,4)), (3, x, (x,0,16)), (x, 9, (x,0,4)), (.1*cos(x)+3.1, .1*sin(x)+(3.1**2), (x,0,6.5)) )
>>> aPlot[0].line_color='r'
>>> aPlot[1].line_color='g'
>>> aPlot.show()
Run Code Online (Sandbox Code Playgroud)