gpt4 book ai didi

python - 3D 堆叠 2D 直方图

转载 作者:行者123 更新时间:2023-12-02 00:40:35 25 4
gpt4 key购买 nike

我有一堆 2D 直方图(方形 2D numpy 数组),我想像这样以 3D 形式堆叠:

Image from Cardenas, Alfredo E., et al. "Unassisted transport of N-acetyl-L-tryptophanamide through membrane: experiment and simulation of kinetics." The Journal of Physical Chemistry B 116.9 (2012): 2739-2750.

(图片来自:Cardenas、Alfredo E. 等人。“N-乙酰基-L-色氨酸酰胺通过膜的无辅助转运:动力学实验和模拟。”物理化学杂志 B 116.9 (2012):2739-第2750章

有人有什么好主意吗?我已经尝试过Python plot - stacked image slices中的contourf方法,但结果并不理想。

最佳答案

我建议您使用 Axes3D.plot_surface 绘制平面,并使用 facecolor 参数为它们着色,如下所示:

import numpy;
from matplotlib import pyplot;
from matplotlib import cm;
from mpl_toolkits.mplot3d import Axes3D;
pyplot.interactive(True);

# Creat mesh.
X = numpy.arange(-1, 1, 0.1);
Y = numpy.arange(-1, 1, 0.1);
X, Y = numpy.meshgrid(X, Y);

# Create some data to plot.
A = numpy.copy(X);
B = numpy.copy(Y);
C = numpy.sqrt(X**2 + Y**2);
D = numpy.cos(C);
# Normalize data for colormap use.
A -= numpy.min(A); A /= numpy.max(A);
B -= numpy.min(B); B /= numpy.max(B);
C -= numpy.min(C); C /= numpy.max(C);
D -= numpy.min(D); D /= numpy.max(D);

# Create flat surface.
Z = numpy.zeros_like(X);

# Plot
fig = pyplot.figure();
ax = fig.gca(projection='3d');
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, facecolors = cm.coolwarm(A));
ax.plot_surface(X, Y, Z+0.1, rstride=1, cstride=1, facecolors = cm.coolwarm(B));
ax.plot_surface(X, Y, Z+0.2, rstride=1, cstride=1, facecolors = cm.coolwarm(C));
ax.plot_surface(X, Y, Z+0.3, rstride=1, cstride=1, facecolors = cm.coolwarm(D));

output of example code

关于python - 3D 堆叠 2D 直方图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20428402/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com