Reputation: 35
This is my code in editor:
import matplotlib.pyplot as plt
import numpy as np
x,y = np.loadtxt('D:\Tanjil\Python\directory\Matplot_trial1.csv',
unpack=True , delimiter='\s')
plt.plot(x,y,'r',label='angle=30 Degree'),
plt.ylabel('Power Input (kW)'),
plt.xlabel('Speed(rpm)'),
plt.axis([750.0, 1400.0, 3.3,3.8])
plt.title('Power Input vs. Speed curve')
plt.legend()
plt.show()
then it shows this:
File "<ipython-input-19-abec5f4efd27>", line 6, in <module>
unpack=True , delimiter='\s')
File "C:\Users\bad_tanjil\Anaconda\lib\site-packages\numpy\lib\npyio.py", line 860, in loadtxt
items = [conv(val) for (conv, val) in zip(converters, vals)]
ValueError: invalid literal for float(): 1350,3.64
Upvotes: 0
Views: 294
Reputation: 69022
You're trying to read a csv document with delimiter='\s'
, but the dcument contains 1350,3.64
somewhere, which are two numbers clearly not whitespace separated. Check your csv, the error originates from there. If it's comma separated, use delimiter=','
.
Also, \s
doesn't mean whitespace separated, it means separated by a literal \s
, whitespace separated is the default when you don't set a delimiter.
Upvotes: 1
Reputation: 965
You should call plt.axis()
with a list of integers like this :
plt.axis([750, 1400, 3, 4])
Upvotes: 1