Created
August 29, 2017 18:57
-
-
Save jmoreno/56b94651c5139b763c7726c044e44295 to your computer and use it in GitHub Desktop.
ManuelBartualPlot.py
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 | |
| # Simple demo with multiple subplots and XKCD FTW!!!. | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import json | |
| import datetime | |
| tweet_ids = [] | |
| retweet_counts = [] | |
| favorite_counts = [] | |
| timestamps = [] | |
| with open('ManuelBartual3.json', 'r') as fp: | |
| backup = json.load(fp) | |
| for iteration in backup: | |
| for tweet in iteration: | |
| created_at = datetime.datetime.strptime(tweet['created_at'], '%a %b %d %X %z %Y') | |
| timestamps.append(created_at) | |
| tweet_ids.append(tweet['id']) | |
| retweet_counts.append(tweet['retweet_count']) | |
| favorite_counts.append(tweet['favorite_count']) | |
| tweet_ids.pop(0) | |
| retweet_counts.pop(0) | |
| favorite_counts.pop(0) | |
| timestamps.pop(0) | |
| x1 = np.array(timestamps) | |
| x2 = np.array(timestamps) | |
| y1 = np.array(retweet_counts) | |
| y2 = np.array(favorite_counts) | |
| with plt.xkcd(): | |
| plt.subplot(2, 1, 1) | |
| plt.plot(x1, y1, 'c.-') | |
| plt.title('Las vacaciones de Manuel Bartual') | |
| # plt.xlabel('Tweets') | |
| plt.ylabel('Retweets') | |
| plt.subplot(2, 1, 2) | |
| plt.plot(x2, y2, 'r.-') | |
| # plt.xlabel('Tweets') | |
| plt.ylabel('Favorites') | |
| plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment