3

I have data that looks like this:

import matplotlib.pyplot as plt
import numpy as np
import sys
import pandas as pd
import seaborn as sns

A = [1,2,3]
A_2 = [1,2,3]
B = [4,5,6]
B_2 = [1,2,1]
C = [7,8,9]
C_2 = [2,3,5]
data = {'A' : A, 'B' : B, 'C' : C}
df =  pd.DataFrame(data)

fig = sns.heatmap(df)
fig.set(yticklabels=['1st', '2nd', '3rd'])
plt.show(fig)

Essentially, I have two tables of data with the exact same dimensions and labels(A,B,C). Now, I'd like to plot them both on the same heatmap but create label grouping.

For instance, in the heatmap, I'd have 6 columns of data: A, A2, B, B2, C, C2, in that exact order and the primary x-labels would just alternate between table1.name and table2.name. Then for every pair, I'd like to have a secondary x-label right below the first one that says A,B,C.

I am able to plot both data tables in the same heatmap by just creating a 25x6 dimension dataframe with all the data, but then I'm unable to create the labels for the x-axis properly.

I'd like to have the x-axis look something like this: enter image description here

How can I achieve this? I saw many posts that do this for bar charts. But I'm having trouble modifying that code for a heat map.

Zephyr
  • 11,891
  • 53
  • 45
  • 80
Jonathan
  • 1,876
  • 2
  • 20
  • 56
  • 2
    There are already some questions in the same direction. E.g. [this one](https://stackoverflow.com/questions/20532614/multiple-lines-of-x-tick-labels-in-matplotlib) or [this one](https://stackoverflow.com/questions/22780563/group-labels-in-matplotlib-barchart-using-pandas-multiindex). Can you say in how far they are not helping here? – ImportanceOfBeingErnest Jan 19 '18 at 09:35
  • I tried approaches similar to both examples, but when I create the minor label, since I'm alternating the same two values three times, the code just treats it as having two columns and aggregates the data into two columns instead of having 6 columns. I hope I'm explaining that clearly. – Jonathan Jan 20 '18 at 05:39
  • 2
    No, a clear explanation would show a [mcve] of the issue. That is exactly what the question should include. Describe problems you have with code by using code. – ImportanceOfBeingErnest Jan 20 '18 at 09:37

0 Answers0