0

I have two matrices: m x m and m x 1.

The 2D matrix's data is dependent on the 1D matrix, so I want to show this case in a one plot.
Earlier, to visualize the 2D matrix I used a heatmap and also now I think about using it.
Both matrices have the same label ticks, so I got an idea to double the 1D matrix and place them next to the 2D matrix's labels to let them share the same label ticks:

heatmap_idea

Is it possible to achieve such a plot^ in Python, especially in seaborn or matplotlib?

Or maybe there is another, better way to visualize such a data?


For now, I see here one issue - a lack of a legend for 1D matrices, but I have no idea where and how it should be placed.

maciejwww
  • 1,067
  • 1
  • 13
  • 26
  • 1
    One option (most intuitive & easiest IMO) is to use the same color scale for all three plots. You'll probably have to compute the limits manually in that case and explicitly set them on the colorbar. This question relates to that: https://stackoverflow.com/questions/3373256/set-colorbar-range-in-matplotlib If you're not satisfied with those results (maybe the scales are too different?), you can construct several subplots or go looking through the matplotlib gallery ( https://matplotlib.org/2.0.2/gallery.html )for ideas. – Sarah Messer Dec 01 '22 at 18:40
  • Maybe. I'll just normalize all values. Thanks! – maciejwww Dec 01 '22 at 19:09
  • 1
    So the two `mx1` vectors are identical? They are not marginal distributions of the two dimensions? If they're marginal distributions, [seaborn jointplot](https://seaborn.pydata.org/tutorial/distributions.html#plotting-joint-and-marginal-distributions) can automatically plot them as 1d histograms. If they are custom vectors, you can use `g.plot_marginals()` to plot custom marginals. – tdy Dec 01 '22 at 19:20
  • Yes, that's the same matrix. I've just wanted to show the dependency of the 2D matrix on the vector's value. – maciejwww Dec 01 '22 at 20:28
  • Make a 2x2 subplot with some appropriate ratios and use imshow on all but the upper-left-hand-corner. Set `sharex='col', sharey='row'` – Mad Physicist Dec 01 '22 at 22:58

0 Answers0