plotting 3 columns from .dat file

Viewed 1648

I have a .dat file with 3 columns that I would like to plot. How can I plot them using matplotlib/ python? I am new to python, the .dat file was created using Fortran 90. A portion of the filename.dat file is below

0.0 0.1 0.85
1.0 0.3 0.62
2.0 0.5 0.27
3.0 0.7 0.34
4.0 0.9 0.19

My python code (not correct) that plots the data in 3D is below.

import numpy as np
import matplotlib.pyplot as plot
from mpl_toolkits.mplot3d import Axes3D

3Dplot.plot(*np.loadtxt("filename.dat",unpack=True), linewidth=2.0) #invalid syntax, why?
3Dplot.show()

What is the equivalent to the GNUplot command

splot 'filename.dat' using 1:2:3

in python? That is what I am trying to do.

However when I run the .py, I get "invalid syntax" error message which I am not sure why, but it is the line that starts with 3D. How can I plot 3d data? I am able to do this if I have a .dat file with only two columns, but when I go to 3 dimensions I do not know what to do. Thanks!

1 Answers
Related