1

Similar questions have been asked in the past in this site - such as Representing 4D data in mplot 3D using colormaps or How to make a 4d plot using Python with matplotlib - but as far as I have found, none of them answers my specific problem.

I have the following data at my disposal:

x1 = numpy.logspace(-100, 20, num=13, base=2) 
x2 = numpy.logspace(-100, 20, num=13, base=2)
x3 = numpy.logspace(-5, 5, num=11, base=10)

y = [...]

So that makes 2 vectors with 13 elements and one vector with 11 elements. Then y is a 13*13*11 variable: i.e. for each combination of elements from x1, x2 and x3 I have a corresponding value in y.

I am wondering if there is any elegant way in Python to visualise this data; I had thought of combining 3D plots with color-mapping as in the links I have posted, however in the examples given in those posts the 3rd variable - x3 - is a function of the other 2, whereas in my case it is y that is a function of x1, x2 and x3.

Would there be any way/trick to achieve this in a single graph or in as few graphs as possible?

Edit: an idea might be to plot for example 11 colormaps, where each colormap corresponds to a value of x3. A dummy example:

Multiple color maps

How could this be achieved?

Community
  • 1
  • 1
Daneel Olivaw
  • 2,077
  • 4
  • 15
  • 23
  • One option would be to plot colored cubes in 3D, as presented [in this question](http://stackoverflow.com/questions/40853556/3d-discrete-heatmap-in-matplotlib). Although I'm not sure, if it's a useful plot, the person asking was very happy about it. You can also think about plotting small balls of different color or so. One problem is that this kind of question is really hard to answer and forces people to actually guess what might be suitable. So I think you need to come up with a kind of plot you want and then ask how to obtain it in matplotlib. – ImportanceOfBeingErnest May 16 '17 at 16:41
  • @ImportanceOfBeingErnest As you state in your answer, it is indeed rather difficult to see anything in there. – Daneel Olivaw May 16 '17 at 17:01
  • You get my point, right? It totally depends on what you want and we cannot guess that. – ImportanceOfBeingErnest May 16 '17 at 17:05
  • 1
    I think that my initial idea is unworkable, as it corresponds basically to your answer to the question you linked to. I have updated my question to give more precision. – Daneel Olivaw May 16 '17 at 17:34

1 Answers1

2

Roughly speaking, you could do something like this:

import matplotlib.pyplot as plt
import numpy as np

x1 = np.logspace(-100, 20, num=13, base=2) 
x2 = np.logspace(-100, 20, num=13, base=2)
x3 = np.logspace(-5, 5, num=11, base=10)
y = np.random.rand(len(x3), len(x2), len(x1))

fig, axes = plt.subplots(ncols=4, nrows=3)
fig.subplots_adjust(right=0.8, wspace=0.25, hspace=0.05)
for i, ax in enumerate(axes.flatten()):
    if i < len(x3):
        ax.set_xticks([0,6,12] )
        ax.set_yticks([0,6,12] )
        ax.set_yticklabels([]); ax.set_xticklabels([])
        im = ax.imshow(y[i, :,:], vmin=0, vmax=1, aspect="equal")
        if i % 4 == 0:
            ax.set_yticklabels([r"$2^{-100}$",r"$2^{-40}$",r"$2^{20}$"])
        if i >=8:
            ax.set_xticklabels([r"$2^{-100}$",r"$2^{-40}$",r"$2^{20}$"])       
    else:
        ax.axis("off")

nax = fig.add_subplot(111, frame_on=False)
nax.set_xticks([])
nax.set_yticks([])
nax.set_xlabel('xlabel', labelpad=20)
nax.set_ylabel('ylabel', labelpad=40)

cbar_ax = fig.add_axes([0.85, 0.15, 0.02, 0.7])
fig.colorbar(im, cax=cbar_ax)

plt.show()

enter image description here

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712