0

I have two dataframes that I feed as input to two heatmap functions in seaborn

df1_data = 
{'0': {'TPUs': 0.0, 'GPUs': 0.0, 'None': 0.0, 'Other': 0.0}, '1-99': {'TPUs': 1.0434782608695652, 'GPUs': 9.18840579710145, 'None': 7.797101449275362, 'Other': 0.8840579710144928}, '100-999': {'TPUs': 1.9855072463768115, 'GPUs': 13.27536231884058, 'None': 10.115942028985508, 'Other': 0.855072463768116}, '1000-9,999': {'TPUs': 2.0434782608695654, 'GPUs': 15.173913043478262, 'None': 9.681159420289855, 'Other': 0.782608695652174}, '10,000-99,999': {'TPUs': 1.0579710144927537, 'GPUs': 8.391304347826088, 'None': 6.449275362318841, 'Other': 0.3188405797101449}, '100,000 or more': {'TPUs': 0.8260869565217391, 'GPUs': 5.27536231884058, 'None': 4.478260869565218, 'Other': 0.37681159420289856}}
df2_data = 
Other  0.0  0.884058   0.855072    0.782609       0.318841         0.376812
{'0': {'TPUs': 0.0, 'GPUs': 0.0, 'None': 0.0, 'Other': 0.0}, '1-99': {'TPUs': 0.09596928982725528, 'GPUs': 1.9193857965451055, 'None': 7.1017274472168905, 'Other': 0.09596928982725528}, '100-999': {'TPUs': 1.055662188099808, 'GPUs': 7.9654510556621885, 'None': 9.692898272552783, 'Other': 0.19193857965451055}, '1000-9,999': {'TPUs': 1.2476007677543186, 'GPUs': 12.667946257197697, 'None': 12.380038387715931, 'Other': 0.4798464491362764}, '10,000-99,999': {'TPUs': 1.055662188099808, 'GPUs': 8.925143953934741, 'None': 10.844529750479847, 'Other': 0.28790786948176583}, '100,000 or more': {'TPUs': 1.8234165067178503, 'GPUs': 10.652591170825335, 'None': 10.652591170825335, 'Other': 0.8637236084452975}}
print(df1)

Q25      0      1-99    100-999  1000-9,999  10,000-99,999  100,000 or more
Q12                                                                        
TPUs   0.0  1.043478   1.985507    2.043478       1.057971         0.826087
GPUs   0.0  9.188406  13.275362   15.173913       8.391304         5.275362
None   0.0  7.797101  10.115942    9.681159       6.449275         4.478261
Other  0.0  0.884058   0.855072    0.782609       0.318841         0.376812

print(df2)
Q25      0      1-99   100-999  1000-9,999  10,000-99,999  100,000 or more
Q12                                                                       
TPUs   0.0  0.095969  1.055662    1.247601       1.055662         1.823417
GPUs   0.0  1.919386  7.965451   12.667946       8.925144        10.652591
None   0.0  7.101727  9.692898   12.380038      10.844530        10.652591
Other  0.0  0.095969  0.191939    0.479846       0.287908         0.863724

Using these two dataframes, I am able to generate two different heatmaps, like, enter image description here

Is it possible combine these two heatmaps into a single heatmap in a triangular format where the upper triangle represents df1 and the lower triangle represents df2 with the same color scale.

It would be great if the plots were made using seaborn

enter image description here

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Rajesh
  • 766
  • 5
  • 17
  • Does this answer your question? [Combine multiple heatmaps in matplotlib](https://stackoverflow.com/questions/17809274/combine-multiple-heatmaps-in-matplotlib) – Pygirl Dec 24 '20 at 14:17
  • The solution in the link provided utilizes matplotlib's scatter function. I was expecting something that used the seaborn's heatmap itself – Rajesh Dec 24 '20 at 14:29
  • It is also difficult to adapt to if the features are categorical – Rajesh Dec 24 '20 at 14:44
  • [Python package to plot two heatmaps in one (split each square into two triangles)](https://stackoverflow.com/questions/63530701/python-package-to-plot-two-heatmaps-in-one-split-each-square-into-two-triangles) – JohanC Dec 24 '20 at 14:45
  • Thank you for your comment @JohanC, the plt.tripcolor in the solution produces an image. So it would be difficult to add annotated values in it – Rajesh Dec 24 '20 at 14:48
  • `plt.tripcolor()` creates a mesh of triangles. With e.g. `plt.text(x, y, f'{value:.2f}')` you can add text, you only have to be careful to add or subtract some offset to have the text near the center of the triangles. Perhaps you need to use a smaller font for everything to fit. – JohanC Dec 24 '20 at 19:02

0 Answers0