I am trying to plot two columns from a text file using python matplotlib but I am getting
ValueError: invalid literal for float(): 148.000000;
This is my python script
import numpy as np
import matplotlib.pyplot as plt
x,y = np.loadtxt('sharma5.txt')
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x,y)
plt.show()
and here is a part of my text file
36.000000 61.000000
36.000000 61.000000
36.000000 148.000000;
36.000000 60.000000
36.000000 120.000000
36.000000 77.000000
36.000000 160.000000
Thanks in advance..
In case you don’t want to fix your data file, you can use the
convertersoption toloadtxtin order to remove any extraneous semicolons. Something likenp.loadtxt("sharma5.txt", converters = {1: lambda s: float(s.strip(";"))})should work.