Skip to content

Instantly share code, notes, and snippets.

@joseph-allen
Created November 26, 2018 12:47
Show Gist options
  • Save joseph-allen/f79c6567a6ace819fe34f68d6160213f to your computer and use it in GitHub Desktop.
Save joseph-allen/f79c6567a6ace819fe34f68d6160213f to your computer and use it in GitHub Desktop.
Plot a pandas dataframe of x over some datetime
import pandas as pd
# Visualisation
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
# Configure visualisations
%matplotlib inline
mpl.style.use( 'ggplot' )
sns.set_style( 'white' )
pylab.rcParams[ 'figure.figsize' ] = 30 , 12
# set x and y values, x must be a datetime
ax = df.plot(x='x', y='y')
# set a locator, set interval
# MicrosecondLocator: locate microseconds
# SecondLocator: locate seconds
# MinuteLocator: locate minutes
# HourLocator: locate hours
# DayLocator: locate specified days of the month
# WeekdayLocator: Locate days of the week, e.g., MO, TU
# MonthLocator: locate months, e.g., 7 for july
# YearLocator: locate years that are multiples of base
ax.xaxis.set_major_locator(mdates.MinuteLocator(interval=5))
# set formatter, see http://strftime.org/
ax.xaxis.set_major_formatter(mdates.DateFormatter('%H-%M-%S'))
plt.title('x over time');
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment