Home > Net >  Incomplete plt.show() figure from pandas dataframe
Incomplete plt.show() figure from pandas dataframe

Time:04-02

I was trying to get a figure from a Pandas dataframe. Apparently an easy job until I got into an unexpected problem I cannot get through : the plt.show() produces a figure showing only 20 lines of the 58 contained in the dataframe. Here is the code with output from the python3 interpreter:

print(df1) #1
         DDgun  mCSM   SDM  DeepDDG  DynaMut2
VARIANT                                      
G39C      -1.4 -0.56 -0.24    -0.75     -0.66
W63R      -0.6 -0.50  0.21    -0.23      0.42
L66P      -1.0 -0.68 -1.17    -0.92     -0.23
A67P      -0.3 -0.28 -0.67    -0.66     -0.19
E68K      -0.3  0.11 -0.04    -0.14      0.10
R70C      -0.7 -0.09 -0.31    -0.93      0.40
R70G      -0.9 -0.14 -0.03    -0.70     -0.26
R70H      -0.3 -0.58 -0.14    -0.62     -0.56
V71M      -0.5 -0.44 -0.66    -1.59     -0.75
E72A      -0.4 -0.40  0.23    -0.42     -0.28
R73P      -0.4  0.26  0.67    -0.59      0.30
G75D       0.0 -0.35  0.17     0.06     -0.46
S76C      -0.1 -0.23  0.71    -0.30     -0.32
V78G      -3.1 -2.05 -2.26    -2.72     -2.32
A80T      -0.9 -1.62 -1.78    -1.99     -1.80
W82G      -5.8 -3.62 -2.07    -4.79     -3.44
V89M      -1.2 -0.75 -2.13    -3.88     -0.59
S93P      -0.2 -0.12 -1.37    -1.99      0.13
G96D      -0.5 -0.62 -0.60    -2.21     -0.08
K97T       0.1 -0.42 -0.64    -0.50     -0.27
W99C      -2.1 -1.40  0.08    -2.01     -0.70
T101I      0.4  0.02 -0.33     0.13      0.38
G103S     -0.7 -1.26 -2.95    -1.97     -0.84
G108V      0.1 -0.38 -2.64    -1.38     -0.97
P114A     -0.4 -2.47  2.10    -2.13     -2.31
P114L      1.7 -3.03  0.62    -2.57     -0.96
P114S     -1.0 -1.00  3.11    -2.07     -3.05
A117D     -3.2 -2.83 -3.66    -5.70     -1.54
A117G     -2.4 -1.71 -2.21    -3.14     -1.92
A117V      0.8 -0.06 -1.14    -1.55     -0.32
Y119C     -3.1 -1.68 -1.59    -0.29     -1.68
L120F     -1.5 -1.49 -1.48    -1.41     -1.16
L120H     -4.2 -2.63 -1.82    -4.87     -0.74
E122D     -0.5 -1.06 -1.40    -1.04     -0.63
C123S     -0.1 -0.46 -1.17    -0.23      0.33
G124S     -0.5 -0.46 -1.17    -0.23     -0.43
G124V      0.1 -0.78 -2.68    -1.56     -1.08
S125F      1.1 -0.43 -2.29    -1.42     -1.12
L128F     -0.6 -1.10  0.52     0.39     -1.69
F129S     -2.1 -1.63 -0.78    -2.32     -2.22
D132A     -0.0 -2.45 -0.64    -2.32      0.04
A140T     -0.3 -0.17  1.18    -0.30     -0.99
L145Q     -1.9 -1.21 -2.54    -1.04     -1.67
Y155N     -4.8 -1.97 -1.76    -1.70     -2.19
V157F     -1.5 -2.34 -2.39    -4.32     -1.32
R170Q     -0.4 -1.32 -1.32    -3.19     -0.61
W296C     -1.1 -0.41 -0.25    -1.12      0.09
F303S     -2.0 -0.41 -0.10    -0.59     -0.44
P304L     -0.7 -1.03 -0.19    -0.83     -0.22
P318T     -1.2 -0.30 -0.58    -0.66     -0.36
P324L     -0.6 -0.73 -0.82    -1.70     -0.22
Y381C     -3.0 -0.28 -0.58    -1.00     -0.14
K463T      0.0 -1.23 -0.37    -1.55     -0.75
L488P     -3.7 -0.92 -0.16    -2.80     -0.85
P499L     -0.4 -1.09 -2.58    -4.06     -0.32
P499R     -0.9 -0.34  0.58    -0.97     -0.56
F512S     -3.5 -0.30  1.20    -1.01     -2.06
L520F     -0.6 -2.25 -0.83    -1.76     -0.66

ax=sns.heatmap(df1,cmap='rocket')

plt.show()

This is the picture I get:

enter image description here

Thanks in advance for your help.

CodePudding user response:

This seems reasonable. I manually added the y ticks AND the y tick labels. To improve the appearance, I used sns.set to adjust the size of the figure.

sns.set(rc = {'figure.figsize':(5, 20)})  # (width_inches, width_height)
ax = sns.heatmap(df1, cmap='rocket')
ax.set_yticks(np.arange(len(df1))   .5)
ax.set_yticklabels(df1.index, fontsize=12)
plt.show()

enter image description here

  • Related