Perfect Plots: Calendarplot

In [1]:
import matplotlib as mpl
import calmap
import pandas as pd
import matplotlib.pyplot as plt

yahoo

In [2]:
df = pd.read_csv('c:/1/yahoo.txt', parse_dates=['date'])
df.set_index('date', inplace=True)
df.head(3)
Out[2]:
VIX.Open VIX.High VIX.Low VIX.Close VIX.Volume VIX.Adjusted year month monthf weekday weekdayf week
date
2007-01-03 12.16 12.75 11.53 12.04 0 12.04 2007 1 Jan 3 Wed 1
2007-01-04 12.40 12.42 11.28 11.51 0 11.51 2007 1 Jan 4 Thu 1
2007-01-05 11.84 12.25 11.68 12.14 0 12.14 2007 1 Jan 5 Fri 1
In [3]:
plt.figure(figsize=(16,10), dpi= 280)
calmap.calendarplot(df['2014']['VIX.Close'],cmap= 'seismic', fig_kws={'figsize': (16,10)}, yearlabel_kws={'color':'black', 'fontsize':24}, subplot_kws={'title':'Yahoo Stock Prices'})
plt.show()
<Figure size 4480x2800 with 0 Axes>

paltes: https://matplotlib.org/examples/color/colormaps_reference.html

cmaps = [(‘Perceptually Uniform Sequential’, [ ‘viridis’, ‘plasma’, ‘inferno’, ‘magma’]), (‘Sequential’, [ ‘Greys’, ‘Purples’, ‘Blues’, ‘Greens’, ‘Oranges’, ‘Reds’, ‘YlOrBr’, ‘YlOrRd’, ‘OrRd’, ‘PuRd’, ‘RdPu’, ‘BuPu’, ‘GnBu’, ‘PuBu’, ‘YlGnBu’, ‘PuBuGn’, ‘BuGn’, ‘YlGn’]), (‘Sequential (2)’, [ ‘binary’, ‘gist_yarg’, ‘gist_gray’, ‘gray’, ‘bone’, ‘pink’, ‘spring’, ‘summer’, ‘autumn’, ‘winter’, ‘cool’, ‘Wistia’, ‘hot’, ‘afmhot’, ‘gist_heat’, ‘copper’]), (‘Diverging’, [ ‘PiYG’, ‘PRGn’, ‘BrBG’, ‘PuOr’, ‘RdGy’, ‘RdBu’, ‘RdYlBu’, ‘RdYlGn’, ‘Spectral’, ‘coolwarm’, ‘bwr’, ‘seismic’]), (‘Qualitative’, [ ‘Pastel1’, ‘Pastel2’, ‘Paired’, ‘Accent’, ‘Dark2’, ‘Set1’, ‘Set2’, ‘Set3’, ‘tab10’, ‘tab20’, ‘tab20b’, ‘tab20c’]), (‘Miscellaneous’, [ ‘flag’, ‘prism’, ‘ocean’, ‘gist_earth’, ‘terrain’, ‘gist_stern’, ‘gnuplot’, ‘gnuplot2’, ‘CMRmap’, ‘cubehelix’, ‘brg’, ‘hsv’, ‘gist_rainbow’, ‘rainbow’, ‘jet’, ‘nipy_spectral’, ‘gist_ncar’])]

In [4]:
df.head(4)
Out[4]:
VIX.Open VIX.High VIX.Low VIX.Close VIX.Volume VIX.Adjusted year month monthf weekday weekdayf week
date
2007-01-03 12.16 12.75 11.53 12.04 0 12.04 2007 1 Jan 3 Wed 1
2007-01-04 12.40 12.42 11.28 11.51 0 11.51 2007 1 Jan 4 Thu 1
2007-01-05 11.84 12.25 11.68 12.14 0 12.14 2007 1 Jan 5 Fri 1
2007-01-08 12.48 12.83 11.78 12.00 0 12.00 2007 1 Jan 1 Mon 2

phone_data

In [5]:
df2 = pd.read_csv('c:/1/phone_data.csv', parse_dates=['date'])
df2.head(3)
Out[5]:
index date duration item month network network_type
0 0 2014-10-15 06:58:00 34.429 data 2014-11 data data
1 1 2014-10-15 06:58:00 13.000 call 2014-11 Vodafone mobile
2 2 2014-10-15 14:46:00 23.000 call 2014-11 Meteor mobile
In [6]:
df2.set_index('date', inplace=True)
df2.head()
Out[6]:
index duration item month network network_type
date
2014-10-15 06:58:00 0 34.429 data 2014-11 data data
2014-10-15 06:58:00 1 13.000 call 2014-11 Vodafone mobile
2014-10-15 14:46:00 2 23.000 call 2014-11 Meteor mobile
2014-10-15 14:48:00 3 4.000 call 2014-11 Tesco mobile
2014-10-15 17:27:00 4 4.000 call 2014-11 Tesco mobile
In [7]:
plt.figure(figsize=(16,10), dpi= 280)
calmap.calendarplot(df2['2014']['duration'],cmap= 'BrBG', how='sum'
                    ,fillcolor='white'
                    , fig_kws={'figsize': (16,10)}
                    , yearlabel_kws={'color':'black', 'fontsize':24}
                    , subplot_kws={'title':'phone_data'})
plt.show()
<Figure size 4480x2800 with 0 Axes>

Energy

In [8]:
df3 = pd.read_csv('c:/2/Energy.csv', index_col=0, parse_dates=['Date'])
df3.set_index('Date', inplace=True)
df3.head()
Out[8]:
Consumption Wind Solar Wind+Solar
Date
2006-01-01 1069.184 NaN NaN NaN
2006-01-02 1380.521 NaN NaN NaN
2006-01-03 1442.533 NaN NaN NaN
2006-01-04 1457.217 NaN NaN NaN
2006-01-05 1477.131 NaN NaN NaN
In [9]:
plt.figure(figsize=(116,100), dpi= 280)

calmap.calendarplot(df3['2007']['Consumption'],cmap= 'YlOrBr', how='sum'
                    ,fillcolor='white'
                    , fig_kws={'figsize': (16,10)}
                    , yearlabel_kws={'color':'gray', 'fontsize':44,'alpha':0.5}
                    , subplot_kws={'title':'Daily power consumption'})

calmap.calendarplot(df3['2008']['Consumption'],cmap= 'YlOrBr', how='sum'
                    ,fillcolor='white'
                    , fig_kws={'figsize': (16,10)}
                    , yearlabel_kws={'color':'gray', 'fontsize':44,'alpha':0.5}
                    , subplot_kws={'title':'Daily power consumption'})

calmap.calendarplot(df3['2009']['Consumption'],cmap= 'YlOrBr', how='sum'
                    ,fillcolor='white', daylabels='PWŚCPSN'
                    , fig_kws={'figsize': (16,10)}
                    , yearlabel_kws={'color':'gray', 'fontsize':44,'alpha':0.5}
                    , subplot_kws={'title':'Daily power consumption'})
Out[9]:
(<Figure size 1152x720 with 1 Axes>,
 array([<matplotlib.axes._subplots.AxesSubplot object at 0x000001C980465198>],
       dtype=object))
<Figure size 32480x28000 with 0 Axes>

Personal calendar

In [10]:
df4 = pd.read_excel('c:/3/wtm.xlsx', parse_dates=['Date'])
df4.set_index('Date', inplace=True)
df4.head()
Out[10]:
Continuous
Date
2018-08-31 65
2018-09-02 60
2018-09-03 75
2018-09-04 120
2018-09-05 120
In [11]:
calmap.calendarplot(df4['2018']['Continuous'],cmap= 'YlGn', how='sum'
                    ,fillcolor='white'
                    , fig_kws={'figsize': (16,10)}
                    , yearlabel_kws={'color':'gray', 'fontsize':44,'alpha':0.5}
                    , subplot_kws={'title':'Personal calendar'})

calmap.calendarplot(df4['2019']['Continuous'],cmap= 'YlGn', how='sum'
                    ,fillcolor='white'
                    , fig_kws={'figsize': (16,10)}
                    , yearlabel_kws={'color':'gray', 'fontsize':44,'alpha':0.5}
                    , subplot_kws={'title':'Personal calendar'})
Out[11]:
(<Figure size 1152x720 with 1 Axes>,
 array([<matplotlib.axes._subplots.AxesSubplot object at 0x000001C98056CF28>],
       dtype=object))