Plot Pandas time series data sampled by day in a heatmap per calendar year, similar to GitHub's contributions plot, using matplotlib.
See the documentation.
To install the latest release via PyPI using pip::
pip install calmap
This project forked from martijnvermaat/calmap
Calendar heatmaps from Pandas time series data
Home Page: https://pythonhosted.org/calmap
License: MIT License
Plot Pandas time series data sampled by day in a heatmap per calendar year, similar to GitHub's contributions plot, using matplotlib.
See the documentation.
To install the latest release via PyPI using pip::
pip install calmap
With Python 3.12:
Python 3.12.1 (v3.12.1:2305ca5144, Dec 7 2023, 17:23:38) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import calmap
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/calmap/__init__.py", line 18, in <module>
from distutils.version import StrictVersion
ModuleNotFoundError: No module named 'distutils'
This is because distutils is no longer part of Python from 3.12 onwards:
A workaround is to install Setuptools, but the recommended advice to to replace distutils.version
with the modern packaging.version
API:
Hello, I have encountered some issues while using the function calmap.calendarplot.
Here is my code:
from doc.Plot.require import *
import calmap
# Import Data
df = pd.read_csv("https://raw.githubusercontent.com/selva86/datasets/master/yahoo.csv", parse_dates=['date'])
# df = pd.read_csv("../data/yahoo.csv", parse_dates=['date'])
df.set_index('date', inplace=True)
# Plot
plt.figure(figsize=(16, 10), dpi=60)
calmap.calendarplot(df[df['year'] == 2014]['VIX.Close'], fig_kws={'figsize': (16, 10)}, how="sum",
yearlabel_kws={'color': 'black', 'fontsize': 14}, subplot_kws={'title': 'Yahoo Stock Prices'})
plt.show()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[49], line 11
9 # Plot
10 plt.figure(figsize=(16, 10), dpi=60)
---> 11 calmap.calendarplot(df[df['year'] == 2014]['VIX.Close'], fig_kws={'figsize': (16, 10)}, how="sum",
12 yearlabel_kws={'color': 'black', 'fontsize': 14}, subplot_kws={'title': 'Yahoo Stock Prices'})
13 plt.show()
File ~\AppData\Roaming\Python\Python39\site-packages\calmap\__init__.py:403, in calendarplot(data, how, yearlabels, yearascending, yearlabel_kws, subplot_kws, gridspec_kws, fig_kws, fig_suptitle, vmin, vmax, **kwargs)
400 max_weeks = 0
402 for year, ax in zip(years, axes):
--> 403 yearplot(by_day, year=year, how=None, ax=ax, **kwargs)
404 max_weeks = max(max_weeks, ax.get_xlim()[1])
406 if yearlabels:
File ~\AppData\Roaming\Python\Python39\site-packages\calmap\__init__.py:202, in yearplot(data, year, how, vmin, vmax, cmap, fillcolor, linewidth, linecolor, daylabels, dayticks, monthlabels, monthticks, monthly_border, ax, **kwargs)
197 by_day.loc[(by_day.index.month == 12) & (by_day.week < 10), "week"] = (
198 by_day.week.max() + 1
199 )
201 # Pivot data on day and week and mask NaN days. (we can also mask the days with 0 counts)
--> 202 plot_data = by_day.pivot("day", "week", "data").values[::-1]
203 plot_data = np.ma.masked_where(np.isnan(plot_data), plot_data)
205 # Do the same for all days of the year, not just those we have data for.
TypeError: pivot() takes 1 positional argument but 4 were given
and the variables df[df['year'] == 2014]['VIX.Close']
output is
df[df['year'] == 2014]['VIX.Close'] output:
date
2014-01-02 14.230000
2014-01-03 13.760000
2014-01-06 13.550000
2014-01-07 12.920000
2014-01-08 12.870000
...
2014-12-24 14.370000
2014-12-26 14.500000
2014-12-29 15.060000
2014-12-30 15.920000
2014-12-31 19.200001
I am uncertain about how to modify this code. Even when I search for examples on Stack Overflow that appear identical, they still result in errors. Could you please guide me on how to modify this code? Thank you.
Todo:
I never got around to migrating this from travisCI to GHA and I've run out of credits over there after they killed the free OS support.
I had to manually deploy 0.0.11
I would welcome a PR helping with this.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.