Im trying to read Data from scv file and plot them.Reading process easily worked but by Plotting is full missed up. I have tried that with MATLAB and even Excel. Both are plotting correct but in python 3 i have problems.it seems like that. Plot Photo with python Plot Photo with MATLAB
I would be thankful for your help
filename1=fd.askopenfilename(title='open expander text data to graphic ')
reader=csv.reader(filename1)
xpoints = []
ypoints = []
for line in reader:
xpoints.append(line[0])
ypoints.append(line[1])
xpoints_to_graph=np.array(xpoints[])
ypoints_to_graph=np.array(ypoints[])
plt.plot(xpoints_to_graph,ypoints_to_graph)
CodePudding user response:
Each line
is a tuple of strings. Thus, xpoints
and ypoints
are lists of strings. Matplotlib will thus attempt to put all possible values as ticks, which is why the plot is so cluttered.
You should treat each element of line
as a number:
xpoints = []
ypoints = []
for line in reader:
xpoints.append(float(line[0]))
ypoints.append(float(line[1]))
Alternatively, use numpy.loadtxt
, which will automatically convert numbers to floating-point or integer types.