In [6]:
# Import basic libs & set default parameters for plot

import numpy as np; np.random.seed(sum(map(ord, 'calmap')))
import pandas as pd
import calmap
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = (20,3)
plt.rcParams["axes.labelweight"] = "bold"
In [2]:
# Import 'Daily' Press Briefing Data

full_df=pd.read_csv('Full_Press_Briefing_Data.csv')
full_df['D']=pd.to_datetime(full_df[['Year', 'Month', 'Day']])
full_df['Is_Briefing_Present']=1
In [3]:
# Create a full calendar date range for 2013-2018. 

full_Calendar=pd.date_range(start='2013-01-01',end='2018-12-31',freq='D')
calendar_df=pd.DataFrame()
calendar_df=calendar_df.assign(D=full_Calendar)

# Merge with Daily Briefing Data. When Daily_Briefing is not present, set it to zero
final_df=calendar_df.merge(full_df[['D','Is_Briefing_Present']],on='D',how='left')
final_df.fillna(0,inplace=True)
In [12]:
# Plot first year for obama

obama_first_year_2013=final_df[final_df.D<'2014-01-01']
obama_first_year_2013.set_index('D',inplace=True)
events_2013 = pd.Series(obama_first_year_2013['Is_Briefing_Present'])
ax=calmap.yearplot(events_2013, year=2013, cmap=plt.cm.Blues, fillcolor=u'whitesmoke', linewidth=1, linecolor=None, daylabels=['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'], dayticks=True, monthlabels=['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], monthticks=True)

font = {'family': 'sans-serif',
        'color':  '#05266d',
        'weight': 'bold',
        'size': 42,
        }

ax.set_ylabel('2013',fontdict=font)
#ax.set_label_position('top')
Out[12]:
Text(0,0.5,'2013')
In [13]:
# Plot second year for obama

obama_second_year_2014=final_df[(final_df.D>='2014-01-01') & (final_df.D<'2015-01-01')]
obama_second_year_2014.set_index('D',inplace=True)
events_2014 = pd.Series(obama_second_year_2014['Is_Briefing_Present'])
ax=calmap.yearplot(events_2014, year=2014, cmap=plt.cm.Blues, fillcolor=u'whitesmoke', linewidth=1, linecolor=None, daylabels=['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'], dayticks=True, monthlabels=['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], monthticks=True)
ax.set_ylabel('2014',fontdict=font)
Out[13]:
Text(0,0.5,'2014')
In [14]:
# Plot first year for Trump

trump_first_year_2017=final_df[(final_df.D>='2017-01-01') & (final_df.D<'2018-01-01')]
trump_first_year_2017.set_index('D',inplace=True)
events_2017 = pd.Series(trump_first_year_2017['Is_Briefing_Present'])
ax=calmap.yearplot(events_2017, year=2017, cmap='OrRd', fillcolor=u'whitesmoke', linewidth=1, linecolor=None, daylabels=['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'], dayticks=True, monthlabels=['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], monthticks=True)

font = {'family': 'sans-serif',
        'color':  '#870801',
        'weight': 'bold',
        'size': 42,
        }

ax.set_ylabel('2017',fontdict=font)
Out[14]:
Text(0,0.5,'2017')
In [15]:
# Plot second year for Trump

trump_second_year_2018=final_df[final_df.D>='2018-01-01']
trump_second_year_2018.set_index('D',inplace=True)
events_2018 = pd.Series(trump_second_year_2018['Is_Briefing_Present'])
ax=calmap.yearplot(events_2018, year=2018, cmap='OrRd', fillcolor=u'whitesmoke', linewidth=1, linecolor=None, daylabels=['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'], dayticks=True, monthlabels=['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], monthticks=True)

ax.set_ylabel('2018',fontdict=font)
Out[15]:
Text(0,0.5,'2018')
In [ ]: