我有三个参数 x y t 。但问题是我的文件结构。

我的文件命名为:

e_x_y.txt
t_x_y.txt

其中 e_x_y.txt x y 的特定值有错误, t_x_y.txt 有相应的时间值。

我需要在 x vs y vs t 图上的 e_x_y.txt 中绘制值。

最好的方法是什么?

我知道x和y值是什么,所以我不必从文件名中扣除它们。


为了使事情更清楚,

假设我的文件是:

e_4_5.txt
45
54
t_4_5.txt
2.0
6.0

e_7_8.txt
32
98
121
t_7_8.txt
2
9
1.0

我想绘制以下几点:

(4,5,2.0) = 45
(4,5,6.0) = 54
(7,8,2.0) = 32 
(7,8,9.0) = 98
(7,8,1.0) = 121
有帮助吗?

解决方案

您尝试制作的地块类型可能很难想象。我可以给你两个建议:一个是你想要的,一个是你应该做的事情......

绘制4-D数据:

为了做到这一点,你必须绘制一系列 x,y,t 点,并以某种方式表示每个点的错误值 e 。您可以通过更改点的颜色或大小来完成此操作。在这个例子中,我将在每个点绘制一个球体,其直径根据误差而变化(直径为1等于最大预期误差)。颜色代表时间。我将使用您添加到问题中的示例数据(格式为 5-by-4 矩阵,其中的列包含 x y t e 数据):

data = [4 5 2 45; 4 5 6 54; 7 8 2 32; 7 8 9 98; 7 8 1 121];
[x, y, z] = sphere;  % Coordinate data for sphere
MAX_ERROR = 121;     % Maximum expected error
for i = 1:size(data, 1)
  c = 0.5*data(i, 4)/MAX_ERROR;  % Scale factor for sphere
  X = x.*c+data(i, 1);           % New X coordinates for sphere
  Y = y.*c+data(i, 2);           % New Y coordinates for sphere
  Z = z.*c+data(i, 3);           % New Z coordinates for sphere
  surface(X, Y, Z, 'EdgeColor', 'none');  % Plot sphere
  hold on
end
grid on
axis equal
view(-27, 16);
xlabel('x');
ylabel('y');
zlabel('t');

这就是它的样子:

问题:虽然情节看起来很有趣,但它不是很直观。此外,以这种方式绘制大量的点将会变得混乱,很难很好地看到它们。

更直观的三维图:

最好是制作数据的三维图,因为它可能更容易解释。这里,x轴表示迭代次数,y轴表示每个单独的网络:

plot3(1:2, [1 1], [2 45; 6 54]);           % Plot data for network 4-5
hold on
plot3(1:3, [2 2 2], [2 32; 9 98; 1 121]);  % Plot data for network 7-8
xlabel('iteration number');
set(gca, 'YTick', [1 2], 'YTickLabel', {'network 4-5', 'network 7-8'})
grid on
legend('time', 'error')
view(-18, 30)

这会产生更清晰的情节:

其他提示

即使我不相信这是可视化数据的最佳方式,但这是一种简单的方法,可以按照您的要求进行。您可以在简单的散点图中绘制3D点,并将大小或颜色映射到第四维 error 的值。类似的东西:

x = randi(20, [10 1]);
y = randi(20, [10 1]);
t = randi(10, [10 1]);
e = randi(200, [10 1]);

% map `e` to color
figure(1)
scatter3(x, y, t, 200, e, 'filled')
xlabel('x'), ylabel('y'), zlabel('t')
colormap(hot), colorbar

% map `e` to size
figure(2)
scatter3(x, y, t, e, 'filled')
xlabel('x'), ylabel('y'), zlabel('t')

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top