-1

UPDATED

I have write down a code like the given bellow..

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

df = pd.read_csv("data_1.csv",index_col="Group")
print df

fig,ax = plt.subplots(1)
heatmap = ax.pcolor(df)########
ax.pcolor(df,edgecolors='k')

cbar = plt.colorbar(heatmap)##########

plt.ylim([0,12])
ax.invert_yaxis()


locs_y, labels_y = plt.yticks(np.arange(0.5, len(df.index), 1), df.index)
locs_x, labels_x = plt.xticks(np.arange(0.5, len(df.columns), 1), df.columns)
ax.set_xticklabels(labels_x, rotation=10)
ax.set_yticklabels(labels_y,fontsize=10)
plt.show()

Which takes input like given bellow and plot a heat map with the two side leabel left and bottom..

GP1,c1,c2,c3,c4,c5
S1,21,21,20,69,30
S2,28,20,20,39,25
S3,20,21,21,44,21

I further want to add additional labels at right side as given bellow to the data and want to plot a heatmap with three side label. right left and bottom.

GP1,c1,c2,c3,c4,c5
S1,21,21,20,69,30,V1
S2,28,20,20,39,25,V2
S3,20,21,21,44,21,V3

What changes should i incorporate into the code.

Please help ..

Community
  • 1
  • 1
jax
  • 3,927
  • 7
  • 41
  • 70

1 Answers1

1

You may create a new axis on the right of the plot, called twinx. Then you need to essentially adjust this axis the same way you already did with the first axis.

u = u"""GP1,c1,c2,c3,c4,c5
S1,21,21,20,69,30
S2,28,20,20,39,25
S3,20,21,21,44,21"""

import io
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

df= pd.read_csv(io.StringIO(u),index_col="GP1")

fig,ax = plt.subplots(1)
heatmap = ax.pcolor(df, edgecolors='k')

cbar = plt.colorbar(heatmap, pad=0.1)

bx = ax.twinx()

ax.set_yticks(np.arange(0.5, len(df.index), 1))
ax.set_xticks(np.arange(0.5, len(df.columns), 1), )
ax.set_xticklabels(df.columns, rotation=10)
ax.set_yticklabels(df.index,fontsize=10)
bx.set_yticks(np.arange(0.5, len(df.index), 1))
bx.set_yticklabels(["V1","V2","V3"],fontsize=10)
ax.set_ylim([0,12])
bx.set_ylim([0,12])
ax.invert_yaxis()
bx.invert_yaxis()

plt.show()

enter image description here

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
  • is there any method to move or set position for colour bar because in my case, original labels, at right side, are over lapping with the reference colour bar. – jax Jan 29 '18 at 04:55
  • In the code above, a padding of `pad=0.1` is chosen. You may change that value, if you like. – ImportanceOfBeingErnest Jan 29 '18 at 08:24