My plotting code doesn't seem to be showing the graph (lines 12 to 59 are probably not breaking it, but I included them just in case - I had data that took a while to put into a sorted list).
I've messed around with it and tried different things but I think the main problem is that I don't understand what figure()
, plt.show()
, import matplotlib.pyplot as plt
, from pylab import *
and some other lines actually mean. I don't know when I need to use them or why I need to use them.
Could someone help me and explain how to draw an .svg of two lists and have it show at the end with details about why each line is included and when I put plt.
in front and when I put ax.
in front and when I don't put anything in front, etc? Sorry this will take so long to answer, but I really don't understand matplotlib or any of the examples on their website.
import matplotlib
matplotlib.use('SVG')
import matplotlib.pyplot as plt
import string, math
from pylab import *
from decimal import *
name = raw_input("Enter the filename:\n")
myfile = open("datafiles/"+name+".data", 'r')
xData = []
yData = []
plots = [name]
mydata = myfile.readlines()
i = 0
N = len(mydata)
while (i < N):
string = mydata[i]
data = [str(x) for x in string.split(" ")]
data=filter(lambda x: len(x)>0, data)
xData.append(data[1])
yData.append(data[2])
i = i + 1
i = 0
while (i < N):
if (float(xData[i]) <= 0):
xData[i] = ""
yData[i] = ""
if (xData[i] == "nan" or xData[i] == "-nan"):
xData[i] = ""
yData[i] = ""
i = i + 1
xData=filter(lambda x: len(x)>0, xData)
yData=filter(lambda x: len(x)>0, yData)
N = len(xData)
i = 0
while (i < N):
xData[i] = float(xData[i])
yData[i] = float(yData[i])
i = i + 1
j = 0
while (j < N):
i = 0
while (i < (N-j-1)):
if (xData[i]>xData[i+1]):
a, b = xData[i], xData[i+1]
xData[i+1], xData[i] = a, b
a, b = yData[i], yData[i+1]
yData[i+1], yData[i] = a, b
i = i + 1
j = j + 1
plot = plt.figure(1)
plt.plot(xData, yData)
plt.show(1)
plt.savefig(name)