可视化2个参数及其结果 [英] Visualising 2 parameters and their results

查看:128
本文介绍了可视化2个参数及其结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为以下两个值尝试不同的值:

There's 2 parameters where I want to try different values for:

a = [0.0, 0.5, 0.6]  # len == 3
b = [0.0, 0.02 , 0.05, 0.1]  # len == 4

对于a的每个值,尝试b的每个值。
这带有3 * 4 = 12个不同的结果。

For each value of a, try each value of b. This comes with 3 * 4 = 12 different results.

我的数据采用

res = [(0.0, 0.0, res1), (0.0, 0.02, res2), ...]

有什么方法可以让我清晰地看到这一点吗?我当时在考虑轮廓/热图或3D平面,但可惜我无法使它正常工作。

Is there any way I can neatly visualise this? I was thinking of a contour/heat map or 3d plane but sadly I cannot get that to work.

推荐答案

有很多不同的选项。无论如何,第一步都需要将您的 res 列表转换成一个numpy数组。

There are many different options. The first step in any case needs to be to convert your res list into a numpy array.

对于许多地块例如 imshow pcolor(mesh) contourf 需要具有三个2D数组,您可以通过调整输入数组的形状(只要顺序正确)来获得它们。

For many plots like imshow, pcolor(mesh) or contourf, you need to have three 2D arrays, which you can obtain via reshaping of your input array (given that it is ordered correctly).

以下显示了您拥有的一些选项:

The following shows some options you have:

res = [(0.0, 0.0, 0.5), (0.0, 0.02, 0.7), (0.0, 0.05, 0.6), (0.0, 0.10, 0.8),
       (0.5, 0.0, 0.4), (0.5, 0.02, 0.6), (0.5, 0.05, 0.5), (0.5, 0.10, 0.7),
       (0.6, 0.0, 0.3), (0.6, 0.02, 0.5), (0.6, 0.05, 0.4), (0.6, 0.10, 0.6)]

import matplotlib.pyplot as plt
import numpy as np

res = np.array(res)
A = res[:,0].reshape(3,4) #A in y direction
B = res[:,1].reshape(3,4)
Z = res[:,2].reshape(3,4)

fig, ((ax, ax2), (ax3, ax4)) = plt.subplots(2,2)
#imshow
im = ax.imshow(Z, origin="lower")
ax.set_xticks(range(len(Z[0,:])))
ax.set_yticks(range(len(Z[:,0])))
ax.set_xticklabels(B[0,:])
ax.set_yticklabels(A[:,0])

#pcolormesh, first need to extend the grid
bp = np.append(B[0,:], [0.15])
ap = np.append(A[:,0], [0.7])
Bp, Ap = np.meshgrid(bp, ap)
ax2.pcolormesh(Bp, Ap, Z)

#contour
ax3.contourf(B, A, Z, levels=np.linspace(Z.min(), Z.max(),5))
#scatter
ax4.scatter(res[:,1], res[:,0], c=res[:,2], s=121)

ax.set_title("imshow")
ax2.set_title("pcolormesh")
ax3.set_title("contourf")
ax4.set_title("scatter")
plt.tight_layout()
fig.colorbar(im, ax=fig.axes, pad=0.05)
plt.show()

这篇关于可视化2个参数及其结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆