Python Graph tan and arctan with python

  • Thread starter Thread starter ver_mathstats
  • Start date Start date
  • Tags Tags
    Graph Python Tan
AI Thread Summary
The discussion revolves around a Python code snippet that uses NumPy and Matplotlib to plot the tangent and arctangent functions over a specified range. The original poster seeks validation of their code and expresses satisfaction with its execution. Participants suggest that to facilitate better evaluation, the poster should provide output results, preferably in text format rather than screenshots. They also recommend adding a line of code to save the plot as a PNG file for easier sharing. Overall, the conversation emphasizes the importance of sharing both code and output for effective feedback in programming discussions.
ver_mathstats
Messages
258
Reaction score
21
Code:
import numpy as np
import matplotlib.pyplot as plt

x=np.arange(-5*np.pi, 5*np.pi, step = 0.02)
plt.ylim(-1, 1)
tan=np.tan(x)
arctan=np.arctan(x)
plt.plot(x,tan)
plt.plot(x,arctan)

Here is the code I came up with using the guide my teacher gave me, is this correct the way I have done it? Thank you.
 
Technology news on Phys.org
Can't you run it and see?
 
  • Like
Likes ver_mathstats and sysprog
phyzguy said:
Can't you run it and see?
Yeah I did, and it went fine I think, I just wanted to make sure it was okay. Thanks for the response though.
 
It looks good to me. I just wanted you to test it for yourself.
 
  • Like
Likes ver_mathstats and sysprog
You showed that you understand that arctan is the inverse of tan, but if you want us to evaluate your code, maybe you could show some of its output.
 
  • Like
Likes ver_mathstats
sysprog said:
You showed that you understand that arctan is the inverse of tan, but if you want us to evaluate your code, maybe you could show some of its output.
Oh okay, like attaching a photo of the results I obtained?
 
ver_mathstats said:
Oh okay, like attaching a photo of the results I obtained?
Maybe a text copy would be better than a screenshot, but the point is that for diagnostic purposes, we're better informed if we can see all of the components -- input, code, and output.
 
ver_mathstats said:
Oh okay, like attaching a photo of the results I obtained?
If you add a line that says:
Python:
plt.savefig("myplot.png")
it will save the plot as a png file which you can then attach to your post using the "Attach Files" button.
 
  • Like
Likes ver_mathstats and sysprog
phyzguy said:
If you add a line that says:
Python:
plt.savefig("myplot.png")
it will save the plot as a png file which you can then attach to your post using the "Attach Files" button.
nice
 
  • Like
Likes ver_mathstats

Similar threads

Replies
6
Views
3K
Replies
21
Views
5K
Replies
15
Views
2K
Replies
2
Views
3K
Replies
1
Views
1K
Back
Top