4

I would like to plot data which is defined only for each unordered pair of distinct elements in a set. This is naturally represented by a lower-- or upper--triangular matrix, with no values on the diagonal. A correlation matrices is an example.

I might plot it like this

import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

mat = np.random.randn(12,12)
# Generate a mask for the upper triangle
mask = np.triu(np.ones_like(mat, dtype=bool))
sns.heatmap(mat, mask=mask, cmap="vlag", square=True, linewidths=.5, cbar=None)

giving

notrotated

But I would prefer to plot it like this

rotated

Or perhaps with the labels showing each once on the hypoteneuse/diagonal would be nicer, rather than repeated on the two sides like I have done.

Is there a natural way to do this with pyplot or seaborn (or R)? I'm sure there's a relatively simple hacky way, but I wonder if there's a package out there that already does something like this. It seems like a natural way to represent symmetric relation data.

postylem
  • 1,185
  • 12
  • 26
  • Hello! Did you get it? I have the same trouble. I've discovered a library that allows representing arrays (or dataframes) as ternary diagrams. It's called Pyrolite, but I would like to do it throughout matplotlib or other frequent library. Thank you! – Miguel Gonzalez Oct 28 '20 at 15:59
  • Here I send you a link that may be useful: https://stackoverflow.com/questions/29512046/how-to-create-ternary-contour-plot-in-python – Miguel Gonzalez Oct 28 '20 at 16:10

0 Answers0