-1

I have a dataframe with 3 columns. Each of the columns contains some "labels". I want to study a correspondence between the labels of the three columns. As such, I created 3 heatmaps, for each pair of columns, that shows the number of times a pair of labels has appeared.

For example:

colA  | colB  | colC

dog     car     USA
cat     plane   Germany
fish    truck   Spain
eagle   bike    France
dog     car     USA
eagle   train   UK

A heat map of the first two columns above is:

dog      2     0     0     0     0
cat      0     1     0     0     0
fish     0     0     1     0     0
eagle    0     0     0     1     1
        car  plane truck bike train

Now, in the same manner, I can create the other two heatmaps. My question is, can I combine two of them (for example keeping the horizontal axis the same and adding two vertical axes, for the other two columns) create a heatmap that includes the entire triplet correspondence?

Sorry if my question seems a bit vague, but I am trying to see if there are ways of visualizing a three-way correspondence in the style of a heatmap.

Qubix
  • 4,161
  • 7
  • 36
  • 73
  • It would help if you explained how that heatmap is supposed to look like. Options may be [heatmap-drawing-circles-within-tiles](https://stackoverflow.com/questions/49163305/seaborn-complex-heatmap-drawing-circles-within-tiles-to-denote-complex-annotat), or [matshow-but-with-triangles](https://stackoverflow.com/questions/44666679/something-like-plt-matshow-but-with-triangles), or [Plotting two distance matrices together on same plot?](https://stackoverflow.com/questions/44291155/plotting-two-distance-matrices-together-on-same-plot) – ImportanceOfBeingErnest Sep 11 '19 at 14:28
  • Also, what if the number of unique categories is not the same for at least two columns? – ImportanceOfBeingErnest Sep 11 '19 at 14:31
  • @ImportanceOfBeingErnest: Regarding the number of unique categories, would it be possible to go down the dataframe until the numbers are equal, even if you stop at different rows for each column? Regarding the style, this https://stackoverflow.com/a/44293388/5016028 would be good, but I have no clue how to adapt it to my situation since I really don't understand the code there. – Qubix Sep 11 '19 at 14:33
  • You have 4 categories in columnA and 5 in columnC. I don't know how that heatmap is supposed to look like. But if you can create the respective matrices of same shape, you can apply any of the links (even without understanding them). – ImportanceOfBeingErnest Sep 11 '19 at 14:38

1 Answers1

1

this link may help you: Combine multiple heatmaps in matplotlib

one of the answers from above link: There are a few options to present 2 datasets together:

Options 1 - draw a heatmap of the difference of 2 datasets (or ratio, whatever is more appropriate in your case)

pcolor(D2-D1)

and then present several of these comparison figures.

Option 2 - present 1 dataset as pcolor, and another as countour:

pcolor(D1)
contour(D2)

If you really need to show N>2 datasets together, I would go with contour or contourf:

contourf(D1,cmap='Blues')
contourf(D2,cmap='Reds', alpha=0.66)
contourf(D2,cmap='Reds', alpha=0.33)

example output of 3 contourf commands

or

contour(D1,cmap='Blues')
contour(D2,cmap='Reds')
contour(D2,cmap='Reds')

example output of 3 contour commands

unfortunately, simiar alpha tricks do not work well with pcolor.

Riddam Jain
  • 117
  • 2