简体   繁体   中英

Visualization of 4D vectors in Python

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: ie 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:

多种颜色图

How could this be achieved?

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()

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM