Last active
September 4, 2018 08:59
-
-
Save yassineAlouini/1d8c7b3eb51d4b4b2712f871ccd72dda to your computer and use it in GitHub Desktop.
One tick per hour matplotlib plot (using pandas)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import matplotlib.pylab as plt | |
import matplotlib.dates as mdates | |
hours = mdates.HourLocator(interval = 1) | |
h_d_fmt = mdates.DateFormatter('%d-%m %H:%M:%S') | |
DATA_PATH = "/path/to/your/data" | |
TMS_COL = "timestamp_column" | |
COL_TO_PLOT = "column_to_plot" | |
fig, ax = plt.subplots(1, 1) | |
df = pd.read_csv(DATA_PATH, parse_dates=[TMS_COL]) | |
df.set_index(TMS_COL).plot(y=COL_TO_PLOT, ax=ax, x_compat=True) | |
ax.xaxis.set_major_locator(hours) | |
ax.xaxis.set_major_formatter(h_d_fmt) | |
fig.autofmt_xdate() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment