1

I want to plot a CCDF graph in Python by reading data from a text file "data.txt". Anyway, I got an error "ValueError: setting an array element with a sequence".

Can anyone help me?

Here is my code in python:

import matplotlib.pyplot as plt
import numpy as np

read = np.loadtxt('data.txt')
with open('data.txt') as f:
    a = [map(float, line.split()) for line in f]

sorted=np.sort(a)

x2 = []
y2 = []
y = 0
for x in sorted: 
    x2.extend([x,x])
    print x2
    y2.append(y)
    y += 1.0 / len(a)
    y2.append(y)

plt.plot(x2,y2)
plt.show()

And here is my text file "data.txt":

9.500000000
2.500000000
3.500000000
4.500000000
6.500000000
1.500000000
13
  • Why do you create the read array and then completely ignore it? Commented Dec 17, 2013 at 3:54
  • This one is not the problem. I can also remove it. Is there a problem with this? Commented Dec 17, 2013 at 4:00
  • hi @user2357112. I had removed it, but the same error still occurs. What should i do? Any change in my code? Commented Dec 17, 2013 at 4:05
  • Can you show us the full trace back? What is the shape of x2 and y2? Commented Dec 17, 2013 at 4:15
  • x2 stands for the sorted data in text file. And y2 stands for CDF which is ranged from 0 to 1. Commented Dec 17, 2013 at 4:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.