[Python] Writing xyz coordinates in a csv file

Discussão em 'Python' iniciado por Stack, Maio 24, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to write the co-ordinates (xyz coordinates) of a double-circle in a csv file.

    I have written following code now.

    import numpy as np
    import matplotlib.pyplot as plt
    import csv

    bLength=2.10e-10
    numPoints=10
    totalLength = bLength * numPoints
    Circumference = totalLength
    radius = Circumference / (2 * np.pi)
    totalAngle=360.0
    angle = 360.0/numPoints

    # define a function frange to include fraction
    def frange(start, stop, step):
    i = start
    while i < stop:
    yield i
    i += step
    # getting the x, y co-ordinates of the two circles displaced by angle/2)
    for i in frange(0.0, 360.0, angle):
    plt.plot(radius * np.cos(i), radius * np.sin(i), 'bo')
    for j in frange(angle/2, 360.0, angle):
    plt.plot(radius * np.cos(j), radius * np.sin(j), 'bo')

    plt.show()


    Here, I get a circle in the graph (in Jupyter Notebook). However, I would like to write the coordinates (xyz) of these circles (double-circle) in a "csv file".

    The syntax may be as follow. However, I am not able to proceed further.

    with open('data.csv', 'w') as f:
    csv.writer(f, delimiter=' ').writerows(f)


    The final output should contain three columns. The first two columns of the csv will come from the above "for loops". The third column of the csv file should be some constant (say 0 or 2.1). How can I do this?

    Continue reading...

Compartilhe esta Página