简体   繁体   English

倾斜轴2D图,其中xy轴成60度而不是90度

[英]tilted axis 2D plot where x y axis make 60 degree rather than 90

I want to plot a distribution in hexagonal lattice like following. 我想像下面那样在六角形格子中绘制分布。

I want to present this data as 2D colormap or bar chart. 我想将此数据显示为2D色彩图或条形图。 Does any one know how to do this? 有谁知道如何做到这一点? I am familiar with octave, python, gnuplot, excel, matlab. 我熟悉八度,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

Here is a solution using patch in MATLAB. 这是在MATLAB中使用patch的解决方案。

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

and this produces 这产生了 在此处输入图片说明

Read the documentation if you need to change the color scheme. 如果需要更改配色方案,请阅读文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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