Ask Your Question
0

plotting tan()

asked 2013-11-16 06:25:31 +0100

leonardo gravatar image

updated 2013-11-16 10:44:06 +0100

kcrisman gravatar image

When I enter these lines:

p = plot(tan(x), x, -pi, pi)
p.show(xmin=-pi, xmax=pi, ymin=-10, ymax=10)

in cloud.sagemath, I get a graph with vertical lines at -pi/2 and pi/2.

Can someone tell me why these asymptotes are drawn? Is there a way to eliminate them?

edit retag flag offensive close merge delete

Comments

Those are NOT asymptotes. They are connecting the top of the randomly selected points super-close to the asymptotes, and so they look like asymptotes. What the answer does is show how to have those not connected.

kcrisman gravatar imagekcrisman ( 2013-11-16 10:45:16 +0100 )edit

Thanks for your comment. It does raise some questions, at least for this novice. How does the answer 'show how to have these not connected'? And how would you plot the graph with 'real' aymptotes (I understand that they would look the same as the connecting lines). I mean, I get that you could just draw vertical lines at multiples of pi/2, but is there an option that has plot(tan(x)...) draw the asymptotes? Thanks for any help.

leonardo gravatar imageleonardo ( 2013-11-19 14:52:44 +0100 )edit

See http://www.sagemath.org/doc/reference/plotting/sage/plot/plot.html#sage.plot.plot.plot and in particular "detect_poles - (Default: False) If set to True poles are detected. If set to “show” vertical asymptotes are drawn."

kcrisman gravatar imagekcrisman ( 2013-11-19 17:28:36 +0100 )edit

As I said to tmonteil (elsewhere on this page), that's what the document says, but it's not what the sage does. When you enter: sage: plot(tan(x), x, -pi, pi, detect_poles=show) you just get the graph of y = tan(x), without asymptotes. I thought perhaps this was because I was trying out cloud.sagemath, but then I tried the line in my downloaded version of sage (Sage Version 5.8, Release Date: 2013-03-15) and got the same result. And it's true if you enlarge the graph thus: sage: p = plot(tan(x), x, -pi, pi, detect_poles=show) sage: (p).show(xmin=-pi, xmax=pi, ymin=-10, ymax=10) I don't think the docs describe this behavior of plot() correctly. If you agree I think I'll send a little note to the people who maintain the docs. I appreciate your patience and interest.

leonardo gravatar imageleonardo ( 2013-11-20 06:27:56 +0100 )edit

I'll put my comments in an answer at this point.

kcrisman gravatar imagekcrisman ( 2013-11-20 08:36:36 +0100 )edit

2 Answers

Sort by » oldest newest most voted
2

answered 2013-11-20 08:41:06 +0100

kcrisman gravatar image

updated 2013-11-20 08:41:35 +0100

Your problem is that you are putting something in for detect_poles that is not 'show'.

Compare the following.

sage: plot(tan(x), x, -pi, pi, detect_poles=True) 
sage: plot(tan(x), x, -pi, pi, detect_poles=show) 
sage: plot(tan(x), x, -pi, pi, detect_poles='show')

The first two are equivalent, because show is an actual function, hence Python evaluates it as a True boolean:

sage: bool(show)
True

But of course that will give the same behavior. You need the quotes in the last one to make the asymptotes appear. That is why the word is given as "show" and not show in the documentation.

That said, this will still be a not-so-helpful graph unless you use additional keywords.

sage: plot(tan(x), x, -pi, pi, detect_poles='show', ymin=-50,ymax=50)

image description

This is also the type of example given in the documentation:

sage: plot(gamma, (-3, 4), detect_poles = 'show').show(ymin = -5, ymax = 5)

Hope this helps!

edit flag offensive delete link more

Comments

Hey, it is great!

gundamlh gravatar imagegundamlh ( 2013-11-20 08:56:56 +0100 )edit

That's it! Thanks so much. You're a very good teacher.

leonardo gravatar imageleonardo ( 2013-11-20 12:30:54 +0100 )edit

Awww, thanks! Enjoy using Sage.

kcrisman gravatar imagekcrisman ( 2013-11-20 21:05:09 +0100 )edit
1

answered 2013-11-16 06:55:17 +0100

tmonteil gravatar image

updated 2013-11-16 06:56:48 +0100

You can try with detect_poles=True :

sage: p = plot(tan(x), x, -pi, pi, detect_poles=True)
sage: p.show(xmin=-pi, xmax=pi, ymin=-10, ymax=10)

You can get the documentation of the plot function by typing:

sage: plot?
edit flag offensive delete link more

Comments

Thanks so much for your prompt and correct advice. 'detect_poles=True' solved the problem. Sage seems wonderful, both the the system and the community! Just a little comment (probably in the wrong place): I also took your advice and tried 'plot?', and I found this - "detect_poles - (Default: False) If set to True poles are detected. If set to “show” vertical asymptotes are drawn." But when I set detect_poles=show, vertical asymptotes were NOT drawn. They WERE drawn when I set detect_poles=False. Seems like perhaps two options are called for: a 'detect_poles' AND a 'show_asymptotes' one. Thanks again.

leonardo gravatar imageleonardo ( 2013-11-16 10:00:28 +0100 )edit

If your problem has been solved, you should accept the answer. That will show everyone a solution has been found and give tmonteil points for helping you.

dazedANDconfused gravatar imagedazedANDconfused ( 2013-11-16 10:05:56 +0100 )edit

I'm not sure how to accept the answer. I clicked the thumbs-up icon and the check-mark icon. Is that all I have to do? Thanks.

leonardo gravatar imageleonardo ( 2013-11-16 10:45:14 +0100 )edit

It's been a while since I've done it myself so I'm not sure. I think there's a check mark located under the the thumbs down symbol and clicking on the check mark changes the color to green, thereby indicating you accept the answer. Only you can see it (if you're logged in) because it's your question to decide whether to accept.

dazedANDconfused gravatar imagedazedANDconfused ( 2013-11-16 14:57:18 +0100 )edit

Thanks dazed, that did it!

leonardo gravatar imageleonardo ( 2013-11-16 16:23:23 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-11-16 06:25:31 +0100

Seen: 2,699 times

Last updated: Nov 20 '13