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


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

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:42 -0800
Organization http://groups.google.com
Message-ID <832db709-4385-489d-921f-82522caf1fc2@l1g2000vbc.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

I see two ways to do this.

The first is similar to what you propose: plot the file twice,
building the command that declares the hexagons in the first pass, and
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
###################################

This method should work with most terminals with a relatively recent
gnuplot.

The second method is specific to the postscript terminal. You can
modify the locally installed copy of the postscript prologue gnuplot
prepends to every ps file it produces, changing one of the point types
to a hexagon. I don't have time to do this, but it should be
straightforward if you have some knowledge of the postscript language.
Once this is done you can just plot the data 'with points pointtype X'
where X is the point type you modified.

Péter Juhász

Back to comp.graphics.apps.gnuplot | Previous | NextPrevious in thread | Next 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