Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.graphics.apps.gnuplot > #928

Re: plot in hexagonal lattice

From Péter Juhász <peter.juhasz83@gmail.com>
Newsgroups comp.graphics.apps.gnuplot
Subject Re: plot in hexagonal lattice
Date 2012-02-10 02:53 -0800
Organization http://groups.google.com
Message-ID <eb1a0442-3272-46fc-8de4-cdc2827dc1ac@m2g2000vbc.googlegroups.com> (permalink)
References <d92bf6e5-34be-4540-96db-90223e53d475@ge5g2000vbb.googlegroups.com>

Show all headers | View raw


On Feb 9, 10:52 am, zsolti elter <elter.zs...@gmail.com> wrote:
> Hello!
>
> I would like to plot data-s in a hexagonal lattice. I have a .dat file
> in which the 1st and 2nd column are the X and Y coordinates of the
> hexagon's centers, and the other columns hold the data, what I want to
> plot in the lattice.
>
> I managed only to plot the datas with pm3d, but I don't know, how to
> plot the lattice grids, and how to plot hexagons. I plotted the datas
> by circles, and I increased the size of it, but it's not the best.
> So I would like to get something like the lattice map on the left part
> of the picture:http://www.kfki.hu/~aekihp/arlhome/images/verona1.gif
>
> For the lattice I guess I should use a loop and set object polygon,
> because from the center of a hexagon ! can evaluate the points of the
> hexagon (and I know the lattice pitch), but I don't know how to read
> in every step only one X and Y value from my data file, and how to
> assign the value of the data (power in my case) to this hexagon.
>
> Thanks for your help!
>
> Best regards,
>
> Zsolti Elter

Method 1: plot the file twice, building up the command that declares
the hexagons in the first pass, plotting them in the second.

######################
reset
fn = 'hexagons.dat'
S = 0.5
C = sqrt(3)/2
A = 1/C
a = 0.95*A

hex_id = 1

cmd = ''

hex_cmd(x, y, c) = sprintf("set obj hex_id poly from %g,%g-a to %g+a*C,
%g-a*S to %g+a*C,%g+a*S to %g,%g+a to %g-a*C,%g+a*S to %g-a*C,%g-a*S
to %g,%g-a fs solid 0.8 border lc pal cb %g lw 2 fc pal cb %g; hex_id
= hex_id + 1;", x,y,x,y,x,y,x,y,x,y,x,y,x,y,c,c)

read_f(x, y, c) = (cmd=cmd.hex_cmd(x, y, c), y)

set term unknown

plot fn u 1:(read_f($1,$2,$3))

set term pop

eval cmd

set size ratio -1
set xr [GPVAL_X_MIN-A:GPVAL_X_MAX+A]
set yr [GPVAL_Y_MIN-A:GPVAL_Y_MAX+A]

plot fn u 1:2:3 w d lc pal notit
########################

Some test data:

########################
3	1.73205080756888	0.627868065218539
2	3.46410161513775	0.0381587751648738
3	5.19615242270663	0.372697677268786
2	6.92820323027551	0.421502736487078
3	8.66025403784439	0.274237128801435
5	1.73205080756888	0.202129157245494
4	3.46410161513775	0.769320237819866
5	5.19615242270663	0.031500208931071
4	6.92820323027551	0.562379837027411
5	8.66025403784439	0.504284749332101
7	1.73205080756888	0.217345187922358
6	3.46410161513775	0.284577491217966
########################

Method 2: this is specific to the postscript terminal. Modify the
postscript prologue gnuplot prepends to every postscript file it
produces and change one of the point types to a hexagon. Once done,
simply plot the data 'with points pointtype X' where X is the
pointtype you've just modified.

Péter Juhász

Back to comp.graphics.apps.gnuplot | Previous | NextPrevious in thread | Find similar


Thread

plot in hexagonal lattice zsolti elter <elter.zsolt@gmail.com> - 2012-02-09 01:52 -0800
  Re: plot in hexagonal lattice Péter Juhász <peter.juhasz83@gmail.com> - 2012-02-10 02:42 -0800
    Re: plot in hexagonal lattice zsolti elter <elter.zsolt@gmail.com> - 2012-02-10 23:16 -0800
  Re: plot in hexagonal lattice Péter Juhász <peter.juhasz83@gmail.com> - 2012-02-10 02:53 -0800

csiph-web