# Python Graphing a cos function

• Python
Gold Member
Python:
r = np.arange(0,400,0.1)
t = np.cos(r)+10
plt.plot(r,t)

How can I use the range of the cos function to look like this

#### Attachments

72.5 KB · Views: 301

Merlin3189
Homework Helper
Gold Member
Do you mean
change t = np.cos(r)+10
to t = np.(cos(r) + 1) edit: or t = 12*(np.cos(r) + 1) ; if np. is not the amplitude
so that the lower extreme is on the y=0 axis?

Gold Member
Do you mean
change t = np.cos(r)+10
to t = np.(cos(r) + 1) edit: or t = 12*(np.cos(r) + 1) ; if np. is not the amplitude
so that the lower extreme is on the y=0 axis?
Theres a syntax error in your code. Also no, I mean that I need to write a cos function that will look like my graph. Or cos^2x function. Both are okay for me

Merlin3189
Homework Helper
Gold Member
Sorry. I'm not a Python person, so I don't know "np." nor "plt." . They look like references to objects defined elsewhere, but there's no way I can see of knowing what those objects are like.

I just noticed that +10 would leave some negative values.

I'm not sure what you want that's different from the graph you're getting? I can't see where it gets the y axis values, but that's probably just how you've labelled the axis.

Arman777
Ibix
What's the wavelength of ##\cos(x)##? What's the wavelength of your graph? What do you need to do to your array ##r## so that the wavelength matches?

What are the minimum and maximum values of ##\cos(x)##? What are the minimum and maximum values of your graph? What do you need to do to make them match?

Arman777
verty
Homework Helper
Have you seen this formula before: ##y = A \cos(\omega t + \phi)##? A is the amplitude, ##\omega## is the angular frequency in radians per second and ##\phi## is the phase angle in radians. You need ##\omega## so that it has completed two revolutions for t = 360 degrees.

Arman777
Gold Member
Python:
r = np.arange(0,400,0.4)
t = (11*np.cos(r/28.7))+11
plt.plot(r,t)
I guess I find it :) , This works well

Last edited: