Save/read data to/from textfile
<p>I have the following two series:</p>

<pre><code>self.MW_x = ..
self.MW_x = .. (from previous calculations)
</code></pre>

<p>and I zip them together like this:</p>

<pre><code>self.MW_final = list(zip(self.MW_x, self.MW_y))
</code></pre>

<p>and try to save them with <code>numpy.savetxt</code></p>

<pre><code>np.savetxt("testfile.txt", self.MW_final, delimiter = ";", header = "x_Value, y_Value")
</code></pre>

<p>If I plot it directly (self.MW_x, self.MW_y) it looks like this, which is perfect:</p>

<p><img src="http://i.stack.imgur.com/XhBYt.png" alt="perfect plot"></p>

<p>but if I try to plot the saved textfile again, it looks like this:</p>

<p><img src="http://i.stack.imgur.com/DRzFt.png" alt="entirely wrong"></p>

<p>I just don't know what happened on the way to the file and back.</p>

<p>Are you tied to exporting it via numpy with the semicolon delimiter? If not, it would be a lot easier to simply export via Pandas as well. i.e.)</p>

<pre><code>df = pd.DataFrame({"x_value":self.MW_x, "y_value": self.MW_y})
df.to_csv("testfile.txt")

df_again = pd.read_csv("testfile.txt")
</code></pre>

<p>Also, in the answer you posted to this question you have:</p>

<pre><code>x_val = df.ix[0:]
y_val = df.ix[1:]
</code></pre>

<p>which is returning <em>rows</em> 0 through N (N = len(df)) for x_val and <em>rows</em> 1 through N for y_val. This is why you're getting two arrays with two different lengths.</p>

<p>To call a column from a pandas DataFrame you can write:</p>

<pre><code>x_val = df['col_name1']
y_val = df['col_name2']
</code></pre>

<p>Or, more simply, if 'col_name2' is your x-axis variable then you can do:</p>

<pre><code>df.set_index('col_name2', inplace = True)
df.plot()
</code></pre>

<p>which will plot the variable 'col_name1' on the y-axis against 'col_name2' on the x-axis.</p>

python numpy save text-files