python - Legend with labels besides seafile heatmap -


i have following code:

from string import letters import numpy np import pandas pd import seaborn sns import matplotlib.pyplot plt  sns.set(style="white")  # compute correlation matrix df = pd.dataframe(np.random.randint(0,100,size=(100, 4)), columns=list('abcd')) corr = df.corr()  # generate mask upper triangle mask = np.zeros_like(corr, dtype=np.bool) mask[np.triu_indices_from(mask)] = true  # set matplotlib figure f, ax = plt.subplots(figsize=(11, 9))  # generate custom diverging colormap cmap = sns.diverging_palette(220, 10, as_cmap=true)  # draw heatmap mask , correct aspect ratio sns.heatmap(corr, mask=mask, cmap=cmap, vmax=.3,             square=true, #xticklabels=5, #yticklabels=5,             linewidths=.5, cbar_kws={"shrink": .5}, ax=ax) plt.show() 

how possible place additional legend right of plot says thinks like:

a: first label b: ... c: ... d: ... 

i have label correlation bar says 'correlation'. data of course not real data.

about first question, here managed do:

import numpy np import pandas pd import seaborn sns import matplotlib.pyplot plt import matplotlib.lines mlines  sns.set(style="white")  cols = list('abcd') # compute correlation matrix df = pd.dataframe(np.random.randint(0,100,size=(100, 4)), columns=cols) corr = df.corr()  # generate mask upper triangle mask = np.zeros_like(corr, dtype=np.bool) mask[np.triu_indices_from(mask)] = true  # set matplotlib figure f, ax = plt.subplots(figsize=(11, 9))  # generate custom diverging colormap cmap = sns.diverging_palette(220, 10, as_cmap=true)  # draw heatmap mask , correct aspect ratio sns.heatmap(corr, mask=mask, cmap=cmap, vmax=.3,             square=true, #xticklabels=5, #yticklabels=5,             linewidths=.5, cbar_kws={"shrink": .5}, ax=ax) pseudo_lines = [] strs = ['first', 'second', 'third', 'fourth'] c, s in zip(cols, strs):     line = mlines.line2d([], [], color='blue',         marker=r"${}:.this.is.my.{}.label$".format(c, s),         markersize=170, linestyle = 'none')     pseudo_lines.append(line) plt.legend(handles=pseudo_lines, labelspacing=2)  plt.show() 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -