Python Forum
How To Export XY Coordinates Of A Function To CSV - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How To Export XY Coordinates Of A Function To CSV (/thread-25913.html)



How To Export XY Coordinates Of A Function To CSV - jrucker00 - Apr-15-2020

How can I output the X and Y coordinates of a mathematical function to a CSV output? As a very basic example, if f(x)=x^2, then how could I generate a CSV file or list with coordinates of this mathematical function for a range 0>x>100? I am able to graph mathematical functions, but have not figured out how to extract the coordinate information.

Thanks!


RE: How To Export XY Coordinates Of A Function To CSV - bowlofred - Apr-15-2020

Are you working with a toolkit, or are you just wanting to roll it yourself? It could be as simple as just creating your domain and then evaluating at every point.

Then print both the point and the function's value at that point.

def square(num):
    return num ** 2

print("X,Y")
domain = range(100)
for x in domain:
    print(f"{x},{square(x)}")