# Plotting f(1),f(2),f(3),...? This post is a wiki. Anyone with karma >750 is welcome to improve it.

Hi, everyone.

I am new to this, and only just beginning to use this stuff. I want to define a function, and see how it behaves. It's a function of natural numbers. How can I plot it (say, f(1),f(2),f(3),...) on the xy-plane?

Best regards,

edit retag close merge delete

Sort by » oldest newest most voted

Here is one example.

f(n)=n^2
list_plot([f(i) for i in range(10)])


But there are many, many ways to do this. For instance, if you are plotting a function that returns an ordered pair, then this might be appropriate.

f(n)=(n,2*n)
points([f(i) for i in range(10)],marker='^')

more

Thanks. Actually my function is recursive, so I should plot (1,f(1)), then compute f(2) using f(1), and then plot (2,f(2)), and so on. But, I get the idea.

See 2D Plotting, consider plot and line.

It may be more comfortable to first calculate your data points (as an numpy array, or a list of tuples) and then try to visualize them using different methods from plotting examples and docs.

more