Skip to content Skip to sidebar Skip to footer

How To Plot Data From Csv For Specific Date And Time Using Matplotlib?

I have written a python program to get data from csv using pandas and plot the data using matplotlib. My code is below with result: import pandas as pd import datetime import csv

Solution 1:

Hacky way

Try this:

import pylab as pl
pl.xticks(rotation = 90)

It will rotate the labels by 90 degrees, thus eliminating overlap.

Cleaner way

Check out this link which describes how to use fig.autofmt_xdate() and let matplotlib pick the best way to format your dates.

Pandas way

Use to_datetime() and set_index with DataFrame.plot():

df.Datetime=pd.to_datetime(df.Datetime)
df.set_index('Datetime')
df['Sensor Value'].plot()

pandas will then take care to plot it nicely for you:

enter image description here

my Dataframe looks like this:

DatetimeSensorValue02017/02/1719:06:17.188212017/02/1719:06:22.3607222017/02/1719:06:27.3487232017/02/1719:06:32.4827242017/02/1719:06:37.5157452017/02/1719:06:42.58070

Post a Comment for "How To Plot Data From Csv For Specific Date And Time Using Matplotlib?"