I seek some help to plot a heat map which should look like this:
The data set that one can use along x axis is an array of years from 1975 to 2018 [1975,.....2018]
For y axis: An array of month [January to December]
For x-y intersection values, as shown in image, one can use 1 or 2 or 3
In the image I added, cross signs represent data gaps and white spaces represent zero(0) values.
Update:
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import numpy as np
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
df = pd.read_csv('Events_in_Month_and_Year.xlsx',encoding = 'unicode_escape',error_bad_lines=False
)
pivoted = df.pivot_table(index='month', columns='year', aggfunc=len, fill_value=0)
pivoted = pivoted.loc[months] # change the order of the rows to be the same as months
for _ in range(20):
# set some random locations to "not filled in"
pivoted.iloc[np.random.randint(0, len(pivoted)), np.random.randint(0, len(pivoted.columns))] = np.nan
max_val = np.nanmax(pivoted.to_numpy())
ax = sns.heatmap(pivoted, cmap=plt.get_cmap('Greys', max_val + 1), vmin=-0.5, vmax=max_val + 0.5)
ax.patch.set_facecolor('white')
ax.patch.set_edgecolor('black') # will be used for hatching
ax.patch.set_hatch('xxxx')
spines = ax.collections[0].colorbar.ax.spines
for s in spines:
spines[s].set_visible(True) # show border around colorbar
plt.tight_layout()
plt.show()
I have tried this code. But getting error
Error tokenizing data. C error: Buffer overflow caught - possible malformed input file