-
-
Save rik0/2479204 to your computer and use it in GitHub Desktop.
Plot week data as subplots
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
# -*- coding: utf-8 -*- | |
""" | |
____________________________________________________________ | |
| +--------------------------------------------------------+ | | |
| ! ^ ___ --- ! | | |
| ! / \ _--_ / \ /\ / \ ! | | |
| ! / \__/ \ / \_-___-- \ / \ ! | | |
| ! / \___/ --__/ --__- ! | | |
| +-------+-------+-------+-------+-------+-------+--------+ | | |
| 04/02 04/03 04/04 04/02 04/03 04/04 04/04 | | |
| Mon Tue Wed Thu Fri Sat Sun | | |
| +--------------------------------------------------------+ | | |
| ! ^ ___ --- ! | | |
| ! / \ _--_ / \ /\ / \ ! | | |
| ! / \__/ \ / \_-___-- \ / \ ! | | |
| ! / \___/ --__/ --__- ! | | |
| +-------+-------+-------+-------+-------+-------+--------+ | | |
| 04/02 04/03 04/04 04/02 04/03 04/04 04/04 | | |
| Mon Tue Wed Thu Fri Sat Sun | | |
____________________________________________________________ | |
1) I would like to see the xticks label for the first plot too, | |
at the moment it is shown only for the second subplot. | |
2) I would like to move the xticks label of 0.5 of the | |
xticks width, at the moment I have: | |
+-------+-------+-------+-------+-------+-------+--------+ | |
04/02 04/03 04/04 04/02 04/03 04/04 04/04 | |
Mon Tue Wed Thu Fri Sat Sun | |
and I would like this: | |
+-------+-------+-------+-------+-------+-------+--------+ | |
04/02 04/03 04/04 04/02 04/03 04/04 04/04 | |
Mon Tue Wed Thu Fri Sat Sun | |
""" | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import matplotlib.dates as mdates | |
import locale | |
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') | |
import datetime as dt | |
def get_dates(start_day, stop_day, year=2012, month=4): | |
dates = [] | |
for day in range(start_day, stop_day): | |
for hour in range(0, 24): | |
dates.append(dt.datetime(year, month, day, hour)) | |
return np.array(dates) | |
DATAW = ( | |
(get_dates(2, 9), np.random.random(24*7)), | |
(get_dates(9, 16), np.random.random(24*7)), | |
) | |
fig = plt.figure() | |
sub = 211 | |
for dates, vals in DATAW: | |
ax = fig.add_subplot(sub) | |
ax.plot(dates, vals, 'o-') | |
ax.xaxis.set_major_locator( mdates.DayLocator() ) | |
ax.xaxis.set_minor_locator( mdates.HourLocator(np.arange(0,25,6)) ) | |
ax.xaxis.set_major_formatter( mdates.DateFormatter(u'%m/%d\n%a') ) | |
## This line kills some labels. | |
## fig.autofmt_xdate(rotation=0, ha='center') | |
plt.setp(ax.get_xticklabels(), visible=True) | |
plt.grid() | |
sub += 1 | |
fig.subplots_adjust(hspace=.5) | |
plt.savefig("CO.pdf") | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment