plotting time and temperature in xy plot

Viewed 35

I want to plot a xy plot where x axis contain temperature values(first column) and y axis contain time in hr:min:sec(second column) .

8.8900  06:09:95.50
9.4500  06:09:00.56
10.5800 08.06:95.48
11.6500 09:07:73.58
56.3650 00:08:00.47
85.7823 07:01:03.23

I just want to plot a xy plot.

I tried code

import numpy as np
import matplotlib.pyplot as plt
data=np.loadtxt("inpdata.txt")
plt.plot(data[:,0],data[:,1])
plt.show()

But it does not give plot.hope experts may help.Thanks.

1 Answers

The simplest approach would be to use pandas.

Load the file as whitespace delimited file into pandas.DataFrame object as:

import pandas as pd
from matplotlib import pyplot as plt

df = pd.read_csv('inpdata.txt', names=['temp', 'time'], delim_whitespace=True)

Then create a line plot with time as x axis:

df.plot.line(x='time')

and show the plot

plt.show()
Related