0% found this document useful (0 votes)
47 views

Basic Coding

The document summarizes a Python script that reads latitude and longitude data from a CSV file called NED.csv, converts the data to floating point numbers, and plots the latitude vs longitude points on a graph. It imports necessary modules, uses csv.reader to extract the 8th and 9th column of data from the file, converts the string data to floats, plots the first 50 points as blue circles connected by lines, and displays the graph using plt.show().

Uploaded by

Syed Masroor Ali
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Basic Coding

The document summarizes a Python script that reads latitude and longitude data from a CSV file called NED.csv, converts the data to floating point numbers, and plots the latitude vs longitude points on a graph. It imports necessary modules, uses csv.reader to extract the 8th and 9th column of data from the file, converts the string data to floats, plots the first 50 points as blue circles connected by lines, and displays the graph using plt.show().

Uploaded by

Syed Masroor Ali
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

OBJECT: To read a CSV file named as NED.

csv, extract its latitude and longitude which is in the 8th and 9th column of NED.csv file respectively and then plot it. CODING: Before starting a program in Python we need to import different modules in order to access their functionality and that modules are imported in the very starting of Python Script. import sys,os,csv #importing the basic modules import IPython #module needed to import for plotting 2D graphics import scipy #scientific module used for engineering purpose import numpy #numeric module again needed for engineering purpose import matplotlib.pyplot as plt # special module used for plotting if __name__=="__main__": #starting the program x = csv.reader(open("NED.csv","rb")) #a command use for reading a CSV file named "NED" data1 = [] #an empty array that will consist latitude data2 = [] #an array that will consist longitude for data in x: #for loop which is used to access the data present in NED.csv file and that NED.csv file's data is currently in 'x' variable data1.append(data[8]) #it will add the 8th column's data of NED file which is the latitude in an array named "data1" data2.append(data[9]) #it will add the 9th column's data of NED file which is the longitude in an array named "data2" for data_converted in range(50): #for loop which is used to access the first 50 rows of NED.csv file b = data_converted + 1 #it is done so that the first row will be ommited because it is the header row containing the names "latitude", "longitude" in NED.csv file data1_converted = float(data1[b]) #in Python by default the data which is readed is considered to be a "string" that's why it has to be converted into floating number so here we have converted the string data1 into floating number in order to plot it (because string can never be plotted) and stored in a variable names data1_converted data2_converted = float(data2[b]) #similarly we have converted the string data2 into floating number in order to plot it and stored it in a variable named "data2_converted" plt.plot(data1_converted,data2_converted,'o-') #the command having syntax "plt.plot(x,y)" will plot the corresponding latitude and longitude. To give the plotted points different shapes and colour we used "-o"

plt.show() #this command will show the plotted points in a new window. #THANK YOU RESULT:

You might also like