Quantcast

rotate labels by data column

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

rotate labels by data column

Grothausmann, Roman Dr.
Dear mailing list members,


Is there any way to plot labels rotated according to angles given by a data column?
All I could find is:
plot ... with labels rotate by X
which, as I understand, only allows a fixed rotation for all labels.

Any help or hints are very much appreciated
Roman

------------------------------------------------------------------------------
_______________________________________________
gnuplot-info mailing list
[hidden email]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-info
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: rotate labels by data column

theozh
well, you could do it with setting labels...

However, the example below is a bit a cumbersome workaround, but it
seems to do the job in a wxt terminal.
- the first data column is used to define the position
- the second data column gives the label text
- the third data column defines the rotation
The first 3 plot command are not plotting anything but extracting
numbers and text into the variables a,b,c.

Hope this helps...
Maybe there is a more elegant version?


reset

$Data <<EOD
1 one -30
2 two -60
3 three -90
4 four -120
5 five -150
6 six -180
7 seven -210
8 eight -240
9 nine -270
10 ten -300
11 eleven -330
12 twelve -360
EOD

set xrange [0:10]
set yrange [0:10]
set size square
unset xtics
unset ytics
n = 12.   # . for floating point division
set angles degrees
do for [i=1:n] {
  plot $Data u 1:(a=$1,0/0) every 1:1:i-2:0:i-1:0 notitle;
  plot $Data u 1:(b=stringcolumn(2),0/0) every 1:1:i-2:0:i-1:0 notitle;
  plot $Data u 1:(c=$3,0/0) every 1:1:i-1:0:i-1:0 notitle;
  set label i center at (5+5*cos(-i/n*360+90)),(5+5*sin(-i/n*360+90))\
sprintf("%s",b) rotate by c font "Arial,20";
  }

  plot $Data u 1:1 notitle     # or whatever else you need to plot


------------------------------------------------------------------------------
_______________________________________________
gnuplot-info mailing list
[hidden email]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-info
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: rotate labels by data column

theozh
sorry, minor correction:

In the following line it should read of course 'a' instead of 'i' within
cos() and sin() for the position of the label.

set label i center at (5+5*cos(-a/n*360+90)),(5+5*sin(-a/n*360+90))\


------------------------------------------------------------------------------
_______________________________________________
gnuplot-info mailing list
[hidden email]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-info
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: rotate labels by data column

Ethan A Merritt-2
In reply to this post by Grothausmann, Roman Dr.
I like the idea, and it requires only a trivial amount of code, so...
in today's CVS (version 5.1)

    http://gnuplot.sourceforge.net/demo_cvs/rotate_labels.html

using theozh's test data:

 plot $Data using 1:2:3:4 with labels rotate variable


Ethan

On Tue, Aug 2, 2016 at 12:07 AM, Grothausmann, Roman Dr. <
[hidden email]> wrote:

> Dear mailing list members,
>
>
> Is there any way to plot labels rotated according to angles given by a
> data column?
> All I could find is:
> plot ... with labels rotate by X
> which, as I understand, only allows a fixed rotation for all labels.
>
> Any help or hints are very much appreciated
> Roman
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> gnuplot-info mailing list
> [hidden email]
> Membership management via:
> https://lists.sourceforge.net/lists/listinfo/gnuplot-info
>
------------------------------------------------------------------------------
_______________________________________________
gnuplot-info mailing list
[hidden email]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-info
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: rotate labels by data column

Grothausmann, Roman Dr.
In reply to this post by theozh
Many thanks theozh! The way of assigning values from data to variables through
empty plot commands was completely new to me. It works great for wxt
(https://github.com/romangrothausmann/KursgleicheNG/blob/8c9eb5c69e77da7e9102beefa8c139d409717719/windrose.gp),
but even though SVG supports rotated labels, the "empty plots" cause SVG
end-tags for groups that have no start-tag which results in invalid SVGs. Is
that expected?

On 02/08/16 23:04, theozh wrote:

> well, you could do it with setting labels...
>
> However, the example below is a bit a cumbersome workaround, but it
> seems to do the job in a wxt terminal.
> - the first data column is used to define the position
> - the second data column gives the label text
> - the third data column defines the rotation
> The first 3 plot command are not plotting anything but extracting
> numbers and text into the variables a,b,c.
>
> Hope this helps...
> Maybe there is a more elegant version?
>
>
> reset
>
> $Data <<EOD
> 1 one -30
> 2 two -60
> 3 three -90
> 4 four -120
> 5 five -150
> 6 six -180
> 7 seven -210
> 8 eight -240
> 9 nine -270
> 10 ten -300
> 11 eleven -330
> 12 twelve -360
> EOD
>
> set xrange [0:10]
> set yrange [0:10]
> set size square
> unset xtics
> unset ytics
> n = 12.   # . for floating point division
> set angles degrees
> do for [i=1:n] {
>   plot $Data u 1:(a=$1,0/0) every 1:1:i-2:0:i-1:0 notitle;
>   plot $Data u 1:(b=stringcolumn(2),0/0) every 1:1:i-2:0:i-1:0 notitle;
>   plot $Data u 1:(c=$3,0/0) every 1:1:i-1:0:i-1:0 notitle;
>   set label i center at (5+5*cos(-i/n*360+90)),(5+5*sin(-i/n*360+90))\
> sprintf("%s",b) rotate by c font "Arial,20";
>   }
>
>   plot $Data u 1:1 notitle     # or whatever else you need to plot
>

------------------------------------------------------------------------------
_______________________________________________
gnuplot-info mailing list
[hidden email]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-info
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: rotate labels by data column

Grothausmann, Roman Dr.
In reply to this post by Ethan A Merritt-2
Many thanks Ethan for the quick implementation. Works great and has no problems
with SVGs:
https://github.com/romangrothausmann/KursgleicheNG/blob/484c11347d2bee7ad3c7503e5126d5d79f01a32a/windrose.gp

Comparing the vector arrow heads and the label placement in my test project,
reveals a slight displacement for 180° rotations which decreases in both
directions towards 0°/360°. I wasn't able to compensate these with offsets.

Thanks again for the quick feature implementation.

On 03/08/16 22:32, Ethan Merritt wrote:

> I like the idea, and it requires only a trivial amount of code, so...
> in today's CVS (version 5.1)
>
>     http://gnuplot.sourceforge.net/demo_cvs/rotate_labels.html
>
> using theozh's test data:
>
>  plot $Data using 1:2:3:4 with labels rotate variable
>
>
> Ethan
>
> On Tue, Aug 2, 2016 at 12:07 AM, Grothausmann, Roman Dr.
> <[hidden email] <mailto:[hidden email]>>
> wrote:
>
>     Dear mailing list members,
>
>
>     Is there any way to plot labels rotated according to angles given by a data
>     column?
>     All I could find is:
>     plot ... with labels rotate by X
>     which, as I understand, only allows a fixed rotation for all labels.
>
>     Any help or hints are very much appreciated
>     Roman
>
>     ------------------------------------------------------------------------------
>     _______________________________________________
>     gnuplot-info mailing list
>     [hidden email] <mailto:[hidden email]>
>     Membership management via:
>     https://lists.sourceforge.net/lists/listinfo/gnuplot-info
>
>

------------------------------------------------------------------------------
_______________________________________________
gnuplot-info mailing list
[hidden email]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-info
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: rotate labels by data column

Ethan A Merritt-2
On Thu, Aug 4, 2016 at 4:28 AM, Grothausmann, Roman Dr. <
[hidden email]> wrote:

> Many thanks Ethan for the quick implementation. Works great and has no
> problems with SVGs:
> https://github.com/romangrothausmann/KursgleicheNG/blob/484c
> 11347d2bee7ad3c7503e5126d5d79f01a32a/windrose.gp
>
> Comparing the vector arrow heads and the label placement in my test
> project, reveals a slight displacement for 180° rotations which decreases
> in both directions towards 0°/360°. I wasn't able to compensate these with
> offsets.
>


That is probably due to imperfect vertical centering in the svg terminal
output.   The various gnuplot terminals are not consistent in placing
vertically-centered text; some align to the text baseline, some to the
midline, and some to whatever is possible. I suspect the svg terminal could
do a better job than it currently does.

   Ethan


>
> Thanks again for the quick feature implementation.
>
> On 03/08/16 22:32, Ethan Merritt wrote:
>
>> I like the idea, and it requires only a trivial amount of code, so...
>> in today's CVS (version 5.1)
>>
>>     http://gnuplot.sourceforge.net/demo_cvs/rotate_labels.html
>>
>> using theozh's test data:
>>
>>  plot $Data using 1:2:3:4 with labels rotate variable
>>
>>
>> Ethan
>>
>> On Tue, Aug 2, 2016 at 12:07 AM, Grothausmann, Roman Dr.
>> <[hidden email] <mailto:grothausmann.roman@mh-
>> hannover.de>>
>> wrote:
>>
>>     Dear mailing list members,
>>
>>
>>     Is there any way to plot labels rotated according to angles given by
>> a data
>>     column?
>>     All I could find is:
>>     plot ... with labels rotate by X
>>     which, as I understand, only allows a fixed rotation for all labels.
>>
>>     Any help or hints are very much appreciated
>>     Roman
>>
>>     ------------------------------------------------------------
>> ------------------
>>     _______________________________________________
>>     gnuplot-info mailing list
>>     [hidden email] <mailto:[hidden email]
>> rceforge.net>
>>     Membership management via:
>>     https://lists.sourceforge.net/lists/listinfo/gnuplot-info
>>
>>
>>
>>
------------------------------------------------------------------------------
_______________________________________________
gnuplot-info mailing list
[hidden email]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-info
Loading...