简体   繁体   中英

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. Does any one know how to do this? I am familiar with 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

Here is a solution using patch in 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

and this produces 在此处输入图片说明

Read the documentation if you need to change the color scheme.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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