Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

i am learning matplotlib python. but there is same problem in this program

import matplotlib.pyplot as plt

x = []
y = []

readf = open('data.txt', 'r')
splitdata = readf.read().split('/n')
readf.close()

for plotpair in splitdata:
  xandy = plotpair.split(',')
  x.append(int(xandy[0]))
  y.append(int(xandy[1]))


plt.plot(x, y)
plt.title('the X title')
plt.xlabel('the x label')
plt.ylabel('the y label')
plt.show()

and data file same dir or valuse is this..

10101,9
93845,8
94847,4
49948,3
85768,5
57684,2
74859,1
93847,6

but error is

Traceback (most recent call last):
File "/home/najeeb/PycharmProjects/matplot-read-file.py", line 16, in <module>
y.append(int(xandy[1]))
ValueError: invalid literal for int() with base 10: '9\n93845'
share|improve this question
    
.split('/n') -> .split('\n') –  mdurant 20 hours ago
    
thank's i am just stupid...thank's –  Najeeb Choudhary 20 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.