pythonplotdata-files

Python - Plot data from a file


I have a large file with data stored in columns like that:

Pression Volume Temperature
2 3 6
4 2 8
5 3 15

I would like to plot together the values from different columns to compare them with the values from an other given column. For example, the pression and the volume in y-axis and the temperature in x-axis.

In my example, it could give something like that:

Where the pression is in blue, the volume in red and the temperature in x-axis.

How can I do it ?

Thank you

EDIT

The values are space separated and the file is a .dat file

I can't get each value by hand, my real file is quite large for it


Solution

  • Here it is:

    df = pd.DataFrame({'Pressure': {0: 2, 1: 4, 2: 5}, 'Volume': {0: 3, 1: 2, 2: 3}, 'Temperature': {0: 6, 1: 8, 2: 15}})
    
    df.plot(x= 'Temperature', y=['Pressure', 'Volume'], marker='o')
    plt.show()
    

    enter image description here

    In response to you comment, if you have a csv file called 'sample.csv' that looks like this:

    Pressure,Volume,Temperature
    2,3,6
    4,2,8
    5,3,15
    

    You can create the dataframe and plot it as shown below:

    df = pd.read_csv('sample.csv')
    df.plot(x= 'Temperature', y=['Pressure', 'Volume'], marker='o')
    plt.show()