The year 2022 is coming soon. There is built-in calendar module and it is just fine, but I hit upon the idea to generate a calendar with python and matplotlib. It might be really a reinvent of a wheel, but it will be more customizable … and FUN!
Here is the Python code to generate calendar with matplotlib.
By running this code, a calendar of December 2021 will be plotted like this.
Color of day
Set the color of day using check_color_day() function. It can control and returns the color for each day according to the weekday and holiday list.
Note: holiday_list is set for Japan (where I am). Holidays are written as a list of tuples. Tuple should be the form of (month, day).
Grid
By default, grid is off but you can enable grid by setting grid=True.This grid is from the matplotlib function.
Fill specific day
By setting fill=True, the days specified with fillday_list are filled with some color. The color is set in fill_box() function.
Run the code above by changing as main(year, month, grid=True, fill=True), a plot with grid and filling is shown.
Annual plot
To plot annual calendar, you can use subplot.
Conclusion
In this post, I showed the python code to generate calendar. It leveraged the plot functions of matplotlib module. Try yourself modifying and generator your own calendar!