-
Notifications
You must be signed in to change notification settings - Fork 0
/
double_col_graph.py
57 lines (47 loc) · 2.09 KB
/
double_col_graph.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'''
Developed by Christianidis Vasileios and Theano Paratzi
This code converts a .txt file containing two vertical columns of numbers, each line seperated by a
tab (example: 123.45 0.12345) (and yes, its a tab, not a space. It is not designed to work with spaces.
( 23.345 7.821 )
and it converts it into a graph, with the first column being the x and the second the y axis. x=f(x)
All you need to do to make it work:
1)Put this file in the same directory as your two-column .txt
2)change the "data" in line 20 of this script, with the name of your file.
3)Run it (in ubuntu: sudo pythonX double_col_graph)
=====================================University Of West Attica=========================================
Any questions: [email protected]
'''
import matplotlib.pyplot as plt
import numpy as np
def double_col_graph():
#open the file with the two columns
data = open("data", "r") #remember to delete the empty lines in the data
#initializing the arrays x,y
x=[]
y=[]
#seperate the two columns x,y so horizontal and vertical axis can be distinct
for line in data: #each time, var line represents each whole line of the file
a,b= line.split(" ") #split the line, where the ' ' gap is. (the gap is a tab, not a space.)
x.append(float(a)) #append var a to x list.need to convert it to float, or it will stay string
y.append(float(b)) #append the var b to y list
#arrays are full
#convert the arrays to np.arrays so that they can be used in the plot function later on.
xi = np.asarray(x)
yi = np.asarray(y)
return xi , yi
'''=================================================MAIN==============================================='''
#z,w = double_col_graph()
'''
#first way to plot
plt.subplot(111)
plt.plot(z,w) #plot the result, horizontal axis is xi and vertical is yi //plt.plot(z, w, 'ro') for dots
#plt.axis('off') #do not display the axis, it may take too much power from the cpu.
plt.show() #show the result
'''
'''
#second way to plot
fig, ax = plt.subplots()
ax.plot(z, w)
#plt.axis('off') #do not display the axis, it takes too much power from the cpu.
plt.show() #show the result
'''