2

I have a csv file that contains the following few lines of data:

# Vertex        X                Y                Z               K_I             K_II             K_III              J
  0       2.100000e+00      2.000000e+00     -1.000000e-04    0.000000e+00   0.000000e+00        0.000000e+00    0.000000e+00    
  1       2.100000e+00      2.000000e+00      1.699733e-01    8.727065e+00  -8.696262e-04        -1.800691e-04   3.465355e-04    
  2       2.100000e+00      2.000000e+00      3.367067e-01    8.907810e+00  -2.548819e-04        -2.789738e-04   3.610383e-04   

I would like to plot:

vertex (first column) versus K_I (5th column)

vertex (first column) versus K_II (6th column)

vertex (first column) versus K_III (7th column)

How do I extract the specific columns from this file and then plot a line graph from the columns? Any help is greatly appreciated!

3 Answers 3

2

To get you started you can look up the CSV library which is made to handle CSVs (as well as tab and other delimited files. There are a couple of options to plot the data, but matplotlib is an excellent option you may want to look at.

And while not exactly what you want, one of my articles on plotting from SQL Server using matplotlib and PyQT was just published that includes some relevant examples of plotting in matplotlib with a PyQT Gui. I don't address pulling the data from a CSV there, though.

Sign up to request clarification or add additional context in comments.

Comments

1

pandas has built-in visualization support which makes this task very simple. It is a lot more straight forward than csv + matplotlib since pandas abstracts that for you.

Comments

1
import pandas as pd
frame = pd.read_csv('filename.csv', index_col=0)
frame.K_I.plot() # Vertex is the x-axis

also "frame.plot()" plots all columns

1 Comment

I got an error message that says: AttributeError: 'DataFrame' object has no attribute 'K_I'

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.