I have three different dataframes that look similar to this:
>>> a b c d
aa 0.1 0.2 0.4 0.8
bb 0.3 0.5 0.9 0.5
cc 0.4 0.2 0.4 0.3
dd 0.8 0.1 0.3 0.4
The only difference between the 3 dataframes is the given numbers.
I am creating through for loop heatmap for each of those dataframe. I would like to give each heatmap different title based on the df name, e.g df1,df2 and df3. This is how i'm trying to do that (I have cut out the calcualtions in the middle because they are not relevant):
dfs=[df1,df2,df3]
for dfx in dfx:
#calculations.......
fix,ax=plt.subplots(figsize=(12,6))
cmap = plt.get_cmap('Greens_r',5)
cmap.set_over('lightgrey')# colour valued l
sns.set(rc={'figure.figsize':(10.7,10.27)})
#Create the heatmap, set title with string of df)
sns.heatmap(str(dfs),square=True,cmap=cmap,vmin=0.001,vmax=0.051,linewidths=.5,cbar_kws=
{"shrink": 0.8}).set_title(str(dfx),fontsize=20,pad=20)
plt.tick_params(axis='x', which='major', labelsize=14, labelbottom = False, bottom=False, top =
False, labeltop=True)
plt.xticks(rotation=70)
so obviously .set_title(str(dfx),fontsize=20,pad=20) just gives me the whole dataframe as string in the title and not the name (df1 for the first chart, df2 for the 2nd) of the df.
I saw this post Get the name of a pandas DataFrame but seems from it that there is no possibility to get the variable name as string.
My end goal is to be able to give different titles to each one of the three graphs (e.g df1,df2,df3) based on the dataframe variable name