Multicolored Plot from SymPy

不羁的心 提交于 2020-07-17 12:33:12

问题


I'm trying to make a plot of the function x^2 in SymPy and want to overlay it with the lines x=3, y=9, and then also draw a circle around certain points. I've done all of the above with the code

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)) )

However, all the curves are blue and I'd like to make each curve a different color. Looking at the documentation didn't tell me how to do this when I have several curves, only when I have one, and my toying around with throwing line_color='red' in several places didn't get me anywhere. Anyone know the appropriate method or a good hack?


回答1:


You've plotted three functions, therefore you have three plots, numbered in the usual way. You can modify the so-called aesthetics of them individually in the following way. Do NOT read the documentation on this point, where it says that line_color should be a function that returns a float. If you do you might spend an hour as I just did down a dark hole.

>>> 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()


来源:https://stackoverflow.com/questions/40751999/multicolored-plot-from-sympy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!