倾斜轴2D绘图,其中x y轴为60度而不是90度

2024-05-31 23:15:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我想画一个六边形格子的分布,如下所示。在

我想用二维彩色图或条形图来表示这些数据。有人知道怎么做吗?我熟悉octave,python,gnuplot,excel,matlab。在

                 1  1  1  1  1  1  1  1
               2   2  2  2  2  2  2  2  2
            3    3   3  3  3  3  3  3  3   3
              2   2   2  2  2  2  2  2  2
                1   1  1  1  1  1  1  1

Tags: 数据excel彩色条形图matlabgnuplot六边形octave
1条回答
网友
1楼 · 发布于 2024-05-31 23:15:50

这是一个在MATLAB中使用^{}的解决方案。在

data = cellfun(@(x) textscan(x, '%f')', importdata('data.txt', sprintf('\n')));
rowLen = cellfun(@numel, data);
nPoints = sum(rowLen);

centerCells = arrayfun(@(l,r) [(-l+1:2:l-1)'*sin(pi/3) -r*1.5*ones(l,1)], ...
    rowLen', 1:numel(rowLen), 'UniformOutput', false);
centers = vertcat(centerCells{:});

hx = linspace(0,2*pi,7)'; 
vertices = reshape(...
            bsxfun(@plus, permute(sin([hx pi/2+hx]), [1 3 2]), ...
                          permute(centers, [3 1 2])), 7 * nPoints, 2);
faces = reshape(1:7*nPoints, 7, nPoints)';
colorData = vertcat(data{:});

patch('Vertices', vertices, 'Faces', faces, ...
    'FaceColor', 'flat', 'FaceVertexCData', colorData); 
axis equal

这就产生了 enter image description here

如果需要更改配色方案,请阅读documentation。在

相关问题 更多 >