Graph tan and arctan with python

In summary, The code shown involves importing numpy and matplotlib, creating an array, setting limits for the plot, and plotting the tangent and arctangent functions. The conversation discusses testing the code and obtaining the desired output, potentially through attaching a photo or saving the plot as a PNG file.
  • #1
ver_mathstats
260
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
  • #2
Can't you run it and see?
 
  • Like
Likes ver_mathstats and sysprog
  • #3
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.
 
  • #4
It looks good to me. I just wanted you to test it for yourself.
 
  • Like
Likes ver_mathstats and sysprog
  • #5
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
  • #6
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?
 
  • #7
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.
 
  • #8
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
  • #9
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

1. What is the purpose of using Python to graph tan and arctan?

The purpose of using Python to graph tan and arctan is to visualize and analyze the relationship between the tangent and inverse tangent functions. This can help in understanding mathematical concepts and solving complex problems.

2. How do I plot a tangent graph in Python?

To plot a tangent graph in Python, you can use the "matplotlib" library. First, import the library and then use the "plot" and "show" functions to generate the graph. You can also customize the graph by adding labels, titles, and changing the colors and line styles.

3. Can I change the scale of the x and y axes in the graph?

Yes, you can change the scale of the x and y axes in the graph by using the "xlim" and "ylim" functions. These functions allow you to specify the minimum and maximum values for the axes, giving you control over the range and scale of the graph.

4. How do I plot the inverse tangent function in Python?

To plot the inverse tangent function (arctan) in Python, you can use the "numpy" library. First, import the library and then use the "arctan" function to generate the values for the graph. Then, plot these values using the "plot" and "show" functions from the "matplotlib" library.

5. Is it possible to plot both the tangent and inverse tangent functions on the same graph?

Yes, it is possible to plot both the tangent and inverse tangent functions on the same graph in Python. You can use the "plot" function multiple times to plot both functions and then use the "legend" function to label each function. This allows for easy comparison and analysis of both functions on the same graph.

Similar threads

  • Programming and Computer Science
Replies
1
Views
588
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
15
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
21
Views
4K
  • Programming and Computer Science
Replies
6
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • Programming and Computer Science
Replies
2
Views
895
  • Programming and Computer Science
Replies
4
Views
4K
  • Programming and Computer Science
Replies
1
Views
2K
Back
Top