How To Graph Points With Sympy?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I need to calculate and graph a function and it's first two derivatives. Then, I need to graph the minimum and maximum points of the original function on the graph. I have calculated these, but am lost as to how to graph the data.
The x values for the minimum/maximum points are
criticalPoints



with the y values being



criticalPointsY



Here is the segment of code where the error appears.



equation=CreateFunction();
firstDeriv=equation.diff(x);
secondDeriv=firstDeriv.diff(x);
print(equation);
criticalPoints=solveset(firstDeriv,x);
criticalPointsY=;
for a in criticalPoints:
criticalPointsY.append(equation.subs(x,a));

p=plot(equation,firstDeriv,secondDeriv,(x,-10,10));
# Need to add the critical points to the graph. We have them, and the
# y values, but need to put them on the graphs.
print(criticalPoints)
print(criticalPointsY);
for a in range(0, len(criticalPoints)):
xval=criticalPoints[a];
yval=criticalPointsY[a];
plt.plot(xval, yval, 'ro')
p.show();
plt.show();


When I run the program, I get this error.
`



Traceback (most recent call last):
File "--------", line 58, in <module>
xval=criticalPoints[a];
TypeError: 'FiniteSet' object does not support indexing


I have tried plotting the points on p and get a different error



 p.plot(criticalPoints,criticalPointsY);
AttributeError: 'Plot' object has no attribute 'plot'


Is there a way to plot points on this graph? (p)










share|improve this question






















  • "'FiniteSet' object does not support indexing" has nothing to do with plottin. A set has no order, so asking for its first or second element makes no sense. Use criticalPoints=list(solveset(firstDeriv,x)). Also, equation=CreateFunction(); is not useful for those who don't know what CreateFunction(); is.

    – user6655984
    Nov 13 '18 at 21:42












  • I have adjusted for the list, but the points plot on a different graph since I am plotting them on "plt." Is there a way to plot them on plot "p"? I receive the second error when I try. Create function returns a function, y, in form of x, from input from the user already collected. I didn't include it for room.

    – Zach
    Nov 14 '18 at 21:36


















0















I need to calculate and graph a function and it's first two derivatives. Then, I need to graph the minimum and maximum points of the original function on the graph. I have calculated these, but am lost as to how to graph the data.
The x values for the minimum/maximum points are
criticalPoints



with the y values being



criticalPointsY



Here is the segment of code where the error appears.



equation=CreateFunction();
firstDeriv=equation.diff(x);
secondDeriv=firstDeriv.diff(x);
print(equation);
criticalPoints=solveset(firstDeriv,x);
criticalPointsY=;
for a in criticalPoints:
criticalPointsY.append(equation.subs(x,a));

p=plot(equation,firstDeriv,secondDeriv,(x,-10,10));
# Need to add the critical points to the graph. We have them, and the
# y values, but need to put them on the graphs.
print(criticalPoints)
print(criticalPointsY);
for a in range(0, len(criticalPoints)):
xval=criticalPoints[a];
yval=criticalPointsY[a];
plt.plot(xval, yval, 'ro')
p.show();
plt.show();


When I run the program, I get this error.
`



Traceback (most recent call last):
File "--------", line 58, in <module>
xval=criticalPoints[a];
TypeError: 'FiniteSet' object does not support indexing


I have tried plotting the points on p and get a different error



 p.plot(criticalPoints,criticalPointsY);
AttributeError: 'Plot' object has no attribute 'plot'


Is there a way to plot points on this graph? (p)










share|improve this question






















  • "'FiniteSet' object does not support indexing" has nothing to do with plottin. A set has no order, so asking for its first or second element makes no sense. Use criticalPoints=list(solveset(firstDeriv,x)). Also, equation=CreateFunction(); is not useful for those who don't know what CreateFunction(); is.

    – user6655984
    Nov 13 '18 at 21:42












  • I have adjusted for the list, but the points plot on a different graph since I am plotting them on "plt." Is there a way to plot them on plot "p"? I receive the second error when I try. Create function returns a function, y, in form of x, from input from the user already collected. I didn't include it for room.

    – Zach
    Nov 14 '18 at 21:36














0












0








0


1






I need to calculate and graph a function and it's first two derivatives. Then, I need to graph the minimum and maximum points of the original function on the graph. I have calculated these, but am lost as to how to graph the data.
The x values for the minimum/maximum points are
criticalPoints



with the y values being



criticalPointsY



Here is the segment of code where the error appears.



equation=CreateFunction();
firstDeriv=equation.diff(x);
secondDeriv=firstDeriv.diff(x);
print(equation);
criticalPoints=solveset(firstDeriv,x);
criticalPointsY=;
for a in criticalPoints:
criticalPointsY.append(equation.subs(x,a));

p=plot(equation,firstDeriv,secondDeriv,(x,-10,10));
# Need to add the critical points to the graph. We have them, and the
# y values, but need to put them on the graphs.
print(criticalPoints)
print(criticalPointsY);
for a in range(0, len(criticalPoints)):
xval=criticalPoints[a];
yval=criticalPointsY[a];
plt.plot(xval, yval, 'ro')
p.show();
plt.show();


When I run the program, I get this error.
`



Traceback (most recent call last):
File "--------", line 58, in <module>
xval=criticalPoints[a];
TypeError: 'FiniteSet' object does not support indexing


I have tried plotting the points on p and get a different error



 p.plot(criticalPoints,criticalPointsY);
AttributeError: 'Plot' object has no attribute 'plot'


Is there a way to plot points on this graph? (p)










share|improve this question














I need to calculate and graph a function and it's first two derivatives. Then, I need to graph the minimum and maximum points of the original function on the graph. I have calculated these, but am lost as to how to graph the data.
The x values for the minimum/maximum points are
criticalPoints



with the y values being



criticalPointsY



Here is the segment of code where the error appears.



equation=CreateFunction();
firstDeriv=equation.diff(x);
secondDeriv=firstDeriv.diff(x);
print(equation);
criticalPoints=solveset(firstDeriv,x);
criticalPointsY=;
for a in criticalPoints:
criticalPointsY.append(equation.subs(x,a));

p=plot(equation,firstDeriv,secondDeriv,(x,-10,10));
# Need to add the critical points to the graph. We have them, and the
# y values, but need to put them on the graphs.
print(criticalPoints)
print(criticalPointsY);
for a in range(0, len(criticalPoints)):
xval=criticalPoints[a];
yval=criticalPointsY[a];
plt.plot(xval, yval, 'ro')
p.show();
plt.show();


When I run the program, I get this error.
`



Traceback (most recent call last):
File "--------", line 58, in <module>
xval=criticalPoints[a];
TypeError: 'FiniteSet' object does not support indexing


I have tried plotting the points on p and get a different error



 p.plot(criticalPoints,criticalPointsY);
AttributeError: 'Plot' object has no attribute 'plot'


Is there a way to plot points on this graph? (p)







python matplotlib sympy graphing






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 21:16









ZachZach

11




11












  • "'FiniteSet' object does not support indexing" has nothing to do with plottin. A set has no order, so asking for its first or second element makes no sense. Use criticalPoints=list(solveset(firstDeriv,x)). Also, equation=CreateFunction(); is not useful for those who don't know what CreateFunction(); is.

    – user6655984
    Nov 13 '18 at 21:42












  • I have adjusted for the list, but the points plot on a different graph since I am plotting them on "plt." Is there a way to plot them on plot "p"? I receive the second error when I try. Create function returns a function, y, in form of x, from input from the user already collected. I didn't include it for room.

    – Zach
    Nov 14 '18 at 21:36


















  • "'FiniteSet' object does not support indexing" has nothing to do with plottin. A set has no order, so asking for its first or second element makes no sense. Use criticalPoints=list(solveset(firstDeriv,x)). Also, equation=CreateFunction(); is not useful for those who don't know what CreateFunction(); is.

    – user6655984
    Nov 13 '18 at 21:42












  • I have adjusted for the list, but the points plot on a different graph since I am plotting them on "plt." Is there a way to plot them on plot "p"? I receive the second error when I try. Create function returns a function, y, in form of x, from input from the user already collected. I didn't include it for room.

    – Zach
    Nov 14 '18 at 21:36

















"'FiniteSet' object does not support indexing" has nothing to do with plottin. A set has no order, so asking for its first or second element makes no sense. Use criticalPoints=list(solveset(firstDeriv,x)). Also, equation=CreateFunction(); is not useful for those who don't know what CreateFunction(); is.

– user6655984
Nov 13 '18 at 21:42






"'FiniteSet' object does not support indexing" has nothing to do with plottin. A set has no order, so asking for its first or second element makes no sense. Use criticalPoints=list(solveset(firstDeriv,x)). Also, equation=CreateFunction(); is not useful for those who don't know what CreateFunction(); is.

– user6655984
Nov 13 '18 at 21:42














I have adjusted for the list, but the points plot on a different graph since I am plotting them on "plt." Is there a way to plot them on plot "p"? I receive the second error when I try. Create function returns a function, y, in form of x, from input from the user already collected. I didn't include it for room.

– Zach
Nov 14 '18 at 21:36






I have adjusted for the list, but the points plot on a different graph since I am plotting them on "plt." Is there a way to plot them on plot "p"? I receive the second error when I try. Create function returns a function, y, in form of x, from input from the user already collected. I didn't include it for room.

– Zach
Nov 14 '18 at 21:36













2 Answers
2






active

oldest

votes


















0














SymPy plots can be combined with p.extend. However, SymPy plot types do not include point plots, which is what you want for critical points. In such cases one should use matplotlib directly, which SymPy would do anyway under the hood.



Here is an example based on your code, but without semicolons, with list comprehension, and with matplotlib used for all plots. Note thatlambdify provides a way to efficiently evaluate a bunch of SymPy expressions at a bunch of points.



from sympy import *
import numpy as np
import matplotlib.pyplot as plt

x = symbols('x')
equation = x*exp(-x**2/10)
firstDeriv = equation.diff(x)
secondDeriv = firstDeriv.diff(x)
criticalPoints = list(solveset(firstDeriv, x))
criticalPointsY = [equation.subs(x, a) for a in criticalPoints]
xx = np.linspace(-10, 10, 1000)
yy = lambdify(x, [equation, firstDeriv, secondDeriv])(xx)
plt.plot(xx, np.transpose(yy))
plt.plot(criticalPoints, criticalPointsY, 'k*')
plt.show()


plot






share|improve this answer























  • These edits work sometimes, but rarely with polynomials. An error is thrown with the line "plt.plot(xx, np.transpose(yy))" stating xx and np.transpose(yy) have different first dimensions, (1000,) and (3,) respectively. I am working on a solution but am confused on why they are outputting in different dimensions. I am testing it with "equation=x**2 +6"

    – Zach
    Nov 15 '18 at 3:28



















0














I have fixed the issue. The dilemma was occurring due to equations who's derivatives would either be nonexistent, or a horizontal line.



x = symbols('x')
UserInput()
equation = CreateFunction()
firstDeriv = equation.diff(x)
secondDeriv = firstDeriv.diff(x)
workingEquations=
hasEquations=False


What I do at this segment is test by converting the equation to a string and see if there is an x value. If one is present, I append the equation to an array we will access later, otherwise, I graph the horizontal line. I also flip a bool to tell us later if we have an equation with a variable.



if(not str(equation).find("x")==-1):
workingEquations.append(equation)
hasEquations=True
print("True")
else:
plt.axhline(y=equation)
if(not str(firstDeriv).find("x")==-1):
workingEquations.append(firstDeriv)
else:
plt.axhline(y=firstDeriv)
if(not str(secondDeriv).find("x")==-1):
workingEquations.append(secondDeriv)
else:
plt.axhline(y=secondDeriv)
try:
criticalPoints = list(solveset(firstDeriv, x))
criticalPointsY = [equation.subs(x, a) for a in criticalPoints]
plt.plot(criticalPoints, criticalPointsY, 'k*')
except:
print("No critical points")


If we have equations, we graph them from that array we appended all non-horizontal equations to.



if(hasEquations):
xx = np.linspace(-10, 10, 1000)
yy = lambdify(x, workingEquations)(xx)
plt.plot(xx, np.transpose(yy))
plt.show()





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53289609%2fhow-to-graph-points-with-sympy%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    SymPy plots can be combined with p.extend. However, SymPy plot types do not include point plots, which is what you want for critical points. In such cases one should use matplotlib directly, which SymPy would do anyway under the hood.



    Here is an example based on your code, but without semicolons, with list comprehension, and with matplotlib used for all plots. Note thatlambdify provides a way to efficiently evaluate a bunch of SymPy expressions at a bunch of points.



    from sympy import *
    import numpy as np
    import matplotlib.pyplot as plt

    x = symbols('x')
    equation = x*exp(-x**2/10)
    firstDeriv = equation.diff(x)
    secondDeriv = firstDeriv.diff(x)
    criticalPoints = list(solveset(firstDeriv, x))
    criticalPointsY = [equation.subs(x, a) for a in criticalPoints]
    xx = np.linspace(-10, 10, 1000)
    yy = lambdify(x, [equation, firstDeriv, secondDeriv])(xx)
    plt.plot(xx, np.transpose(yy))
    plt.plot(criticalPoints, criticalPointsY, 'k*')
    plt.show()


    plot






    share|improve this answer























    • These edits work sometimes, but rarely with polynomials. An error is thrown with the line "plt.plot(xx, np.transpose(yy))" stating xx and np.transpose(yy) have different first dimensions, (1000,) and (3,) respectively. I am working on a solution but am confused on why they are outputting in different dimensions. I am testing it with "equation=x**2 +6"

      – Zach
      Nov 15 '18 at 3:28
















    0














    SymPy plots can be combined with p.extend. However, SymPy plot types do not include point plots, which is what you want for critical points. In such cases one should use matplotlib directly, which SymPy would do anyway under the hood.



    Here is an example based on your code, but without semicolons, with list comprehension, and with matplotlib used for all plots. Note thatlambdify provides a way to efficiently evaluate a bunch of SymPy expressions at a bunch of points.



    from sympy import *
    import numpy as np
    import matplotlib.pyplot as plt

    x = symbols('x')
    equation = x*exp(-x**2/10)
    firstDeriv = equation.diff(x)
    secondDeriv = firstDeriv.diff(x)
    criticalPoints = list(solveset(firstDeriv, x))
    criticalPointsY = [equation.subs(x, a) for a in criticalPoints]
    xx = np.linspace(-10, 10, 1000)
    yy = lambdify(x, [equation, firstDeriv, secondDeriv])(xx)
    plt.plot(xx, np.transpose(yy))
    plt.plot(criticalPoints, criticalPointsY, 'k*')
    plt.show()


    plot






    share|improve this answer























    • These edits work sometimes, but rarely with polynomials. An error is thrown with the line "plt.plot(xx, np.transpose(yy))" stating xx and np.transpose(yy) have different first dimensions, (1000,) and (3,) respectively. I am working on a solution but am confused on why they are outputting in different dimensions. I am testing it with "equation=x**2 +6"

      – Zach
      Nov 15 '18 at 3:28














    0












    0








    0







    SymPy plots can be combined with p.extend. However, SymPy plot types do not include point plots, which is what you want for critical points. In such cases one should use matplotlib directly, which SymPy would do anyway under the hood.



    Here is an example based on your code, but without semicolons, with list comprehension, and with matplotlib used for all plots. Note thatlambdify provides a way to efficiently evaluate a bunch of SymPy expressions at a bunch of points.



    from sympy import *
    import numpy as np
    import matplotlib.pyplot as plt

    x = symbols('x')
    equation = x*exp(-x**2/10)
    firstDeriv = equation.diff(x)
    secondDeriv = firstDeriv.diff(x)
    criticalPoints = list(solveset(firstDeriv, x))
    criticalPointsY = [equation.subs(x, a) for a in criticalPoints]
    xx = np.linspace(-10, 10, 1000)
    yy = lambdify(x, [equation, firstDeriv, secondDeriv])(xx)
    plt.plot(xx, np.transpose(yy))
    plt.plot(criticalPoints, criticalPointsY, 'k*')
    plt.show()


    plot






    share|improve this answer













    SymPy plots can be combined with p.extend. However, SymPy plot types do not include point plots, which is what you want for critical points. In such cases one should use matplotlib directly, which SymPy would do anyway under the hood.



    Here is an example based on your code, but without semicolons, with list comprehension, and with matplotlib used for all plots. Note thatlambdify provides a way to efficiently evaluate a bunch of SymPy expressions at a bunch of points.



    from sympy import *
    import numpy as np
    import matplotlib.pyplot as plt

    x = symbols('x')
    equation = x*exp(-x**2/10)
    firstDeriv = equation.diff(x)
    secondDeriv = firstDeriv.diff(x)
    criticalPoints = list(solveset(firstDeriv, x))
    criticalPointsY = [equation.subs(x, a) for a in criticalPoints]
    xx = np.linspace(-10, 10, 1000)
    yy = lambdify(x, [equation, firstDeriv, secondDeriv])(xx)
    plt.plot(xx, np.transpose(yy))
    plt.plot(criticalPoints, criticalPointsY, 'k*')
    plt.show()


    plot







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 15 '18 at 1:15







    user6655984



















    • These edits work sometimes, but rarely with polynomials. An error is thrown with the line "plt.plot(xx, np.transpose(yy))" stating xx and np.transpose(yy) have different first dimensions, (1000,) and (3,) respectively. I am working on a solution but am confused on why they are outputting in different dimensions. I am testing it with "equation=x**2 +6"

      – Zach
      Nov 15 '18 at 3:28


















    • These edits work sometimes, but rarely with polynomials. An error is thrown with the line "plt.plot(xx, np.transpose(yy))" stating xx and np.transpose(yy) have different first dimensions, (1000,) and (3,) respectively. I am working on a solution but am confused on why they are outputting in different dimensions. I am testing it with "equation=x**2 +6"

      – Zach
      Nov 15 '18 at 3:28

















    These edits work sometimes, but rarely with polynomials. An error is thrown with the line "plt.plot(xx, np.transpose(yy))" stating xx and np.transpose(yy) have different first dimensions, (1000,) and (3,) respectively. I am working on a solution but am confused on why they are outputting in different dimensions. I am testing it with "equation=x**2 +6"

    – Zach
    Nov 15 '18 at 3:28






    These edits work sometimes, but rarely with polynomials. An error is thrown with the line "plt.plot(xx, np.transpose(yy))" stating xx and np.transpose(yy) have different first dimensions, (1000,) and (3,) respectively. I am working on a solution but am confused on why they are outputting in different dimensions. I am testing it with "equation=x**2 +6"

    – Zach
    Nov 15 '18 at 3:28














    0














    I have fixed the issue. The dilemma was occurring due to equations who's derivatives would either be nonexistent, or a horizontal line.



    x = symbols('x')
    UserInput()
    equation = CreateFunction()
    firstDeriv = equation.diff(x)
    secondDeriv = firstDeriv.diff(x)
    workingEquations=
    hasEquations=False


    What I do at this segment is test by converting the equation to a string and see if there is an x value. If one is present, I append the equation to an array we will access later, otherwise, I graph the horizontal line. I also flip a bool to tell us later if we have an equation with a variable.



    if(not str(equation).find("x")==-1):
    workingEquations.append(equation)
    hasEquations=True
    print("True")
    else:
    plt.axhline(y=equation)
    if(not str(firstDeriv).find("x")==-1):
    workingEquations.append(firstDeriv)
    else:
    plt.axhline(y=firstDeriv)
    if(not str(secondDeriv).find("x")==-1):
    workingEquations.append(secondDeriv)
    else:
    plt.axhline(y=secondDeriv)
    try:
    criticalPoints = list(solveset(firstDeriv, x))
    criticalPointsY = [equation.subs(x, a) for a in criticalPoints]
    plt.plot(criticalPoints, criticalPointsY, 'k*')
    except:
    print("No critical points")


    If we have equations, we graph them from that array we appended all non-horizontal equations to.



    if(hasEquations):
    xx = np.linspace(-10, 10, 1000)
    yy = lambdify(x, workingEquations)(xx)
    plt.plot(xx, np.transpose(yy))
    plt.show()





    share|improve this answer



























      0














      I have fixed the issue. The dilemma was occurring due to equations who's derivatives would either be nonexistent, or a horizontal line.



      x = symbols('x')
      UserInput()
      equation = CreateFunction()
      firstDeriv = equation.diff(x)
      secondDeriv = firstDeriv.diff(x)
      workingEquations=
      hasEquations=False


      What I do at this segment is test by converting the equation to a string and see if there is an x value. If one is present, I append the equation to an array we will access later, otherwise, I graph the horizontal line. I also flip a bool to tell us later if we have an equation with a variable.



      if(not str(equation).find("x")==-1):
      workingEquations.append(equation)
      hasEquations=True
      print("True")
      else:
      plt.axhline(y=equation)
      if(not str(firstDeriv).find("x")==-1):
      workingEquations.append(firstDeriv)
      else:
      plt.axhline(y=firstDeriv)
      if(not str(secondDeriv).find("x")==-1):
      workingEquations.append(secondDeriv)
      else:
      plt.axhline(y=secondDeriv)
      try:
      criticalPoints = list(solveset(firstDeriv, x))
      criticalPointsY = [equation.subs(x, a) for a in criticalPoints]
      plt.plot(criticalPoints, criticalPointsY, 'k*')
      except:
      print("No critical points")


      If we have equations, we graph them from that array we appended all non-horizontal equations to.



      if(hasEquations):
      xx = np.linspace(-10, 10, 1000)
      yy = lambdify(x, workingEquations)(xx)
      plt.plot(xx, np.transpose(yy))
      plt.show()





      share|improve this answer

























        0












        0








        0







        I have fixed the issue. The dilemma was occurring due to equations who's derivatives would either be nonexistent, or a horizontal line.



        x = symbols('x')
        UserInput()
        equation = CreateFunction()
        firstDeriv = equation.diff(x)
        secondDeriv = firstDeriv.diff(x)
        workingEquations=
        hasEquations=False


        What I do at this segment is test by converting the equation to a string and see if there is an x value. If one is present, I append the equation to an array we will access later, otherwise, I graph the horizontal line. I also flip a bool to tell us later if we have an equation with a variable.



        if(not str(equation).find("x")==-1):
        workingEquations.append(equation)
        hasEquations=True
        print("True")
        else:
        plt.axhline(y=equation)
        if(not str(firstDeriv).find("x")==-1):
        workingEquations.append(firstDeriv)
        else:
        plt.axhline(y=firstDeriv)
        if(not str(secondDeriv).find("x")==-1):
        workingEquations.append(secondDeriv)
        else:
        plt.axhline(y=secondDeriv)
        try:
        criticalPoints = list(solveset(firstDeriv, x))
        criticalPointsY = [equation.subs(x, a) for a in criticalPoints]
        plt.plot(criticalPoints, criticalPointsY, 'k*')
        except:
        print("No critical points")


        If we have equations, we graph them from that array we appended all non-horizontal equations to.



        if(hasEquations):
        xx = np.linspace(-10, 10, 1000)
        yy = lambdify(x, workingEquations)(xx)
        plt.plot(xx, np.transpose(yy))
        plt.show()





        share|improve this answer













        I have fixed the issue. The dilemma was occurring due to equations who's derivatives would either be nonexistent, or a horizontal line.



        x = symbols('x')
        UserInput()
        equation = CreateFunction()
        firstDeriv = equation.diff(x)
        secondDeriv = firstDeriv.diff(x)
        workingEquations=
        hasEquations=False


        What I do at this segment is test by converting the equation to a string and see if there is an x value. If one is present, I append the equation to an array we will access later, otherwise, I graph the horizontal line. I also flip a bool to tell us later if we have an equation with a variable.



        if(not str(equation).find("x")==-1):
        workingEquations.append(equation)
        hasEquations=True
        print("True")
        else:
        plt.axhline(y=equation)
        if(not str(firstDeriv).find("x")==-1):
        workingEquations.append(firstDeriv)
        else:
        plt.axhline(y=firstDeriv)
        if(not str(secondDeriv).find("x")==-1):
        workingEquations.append(secondDeriv)
        else:
        plt.axhline(y=secondDeriv)
        try:
        criticalPoints = list(solveset(firstDeriv, x))
        criticalPointsY = [equation.subs(x, a) for a in criticalPoints]
        plt.plot(criticalPoints, criticalPointsY, 'k*')
        except:
        print("No critical points")


        If we have equations, we graph them from that array we appended all non-horizontal equations to.



        if(hasEquations):
        xx = np.linspace(-10, 10, 1000)
        yy = lambdify(x, workingEquations)(xx)
        plt.plot(xx, np.transpose(yy))
        plt.show()






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 '18 at 4:32









        ZachZach

        11




        11



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53289609%2fhow-to-graph-points-with-sympy%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

            Edmonton

            Crossroads (UK TV series)