Menu

#435 Calculate with coordinates and coordinate variables

open
nobody
None
5
2016-04-11
2016-02-04
No

In gnuplot, coordinates for arrow, key, label, and object can be specified in various coordinate systems, even mixed within one location:

set label 'foo' at first 5,graph 0.5
set arrow from 0,0 to first 5,graph 0.5

Not possible is to store coordinates in a variable or to calculate with coordinates. This would be useful in some cases. Syntax could look like this:

Save coordinates in variables:

A = coordinates first 5,graph 0.5
set label 'Hi' at A
set arrow from 0,0 to A

Calculate with coordinates:

A = coordinates first 5,graph 0.5 + graph 0.1,screen 0.1
B = coordinates A - second 0.2,5
set arrow from graph 0.5,0.5 + first 0.1,second 0.3 rto graph 0.1,0.2
set label 'foo' at A
set label 'bar' at B

Discussion

  • Ethan Merritt

    Ethan Merritt - 2016-04-05

    You can already do this using macros, right?

    A = "coordinates first 5,graph 0.5"
    set label 'Hi' at @A
    set arrow from 0,0 to @A
    
     

    Last edit: Ethan Merritt 2016-04-05
  • Harald Harders

    Harald Harders - 2016-04-10

    Hi,

    I didn't know about the macros. However, macros only allow half of my feature request. So, saving coordinates in variables is possible. But do they allow calculation with coordinates?

    Something like this is not possible, right?

    A = "coordinates first 5, graph 0.5"
    B = "coordinates graph 0.1,0.1"
    set label 'Hi' at @A+@B

     
  • Ethan Merritt

    Ethan Merritt - 2016-04-10

    That would not be possible, even in principle. The "first" and "second" axis coordinates can only be calculated in the context of a particular plot being drawn to a particular terminal. Before you issue a plot command there is no way to evaluate their value, let alone before you have done a "set term".

     
  • Harald Harders

    Harald Harders - 2016-04-11

    I agree that such calculations are not possible at the time of executing the "set label" command. But they would be possible at the time of generating the plot. So if such calculations would
    be stored in form of macros when defining them (in set label, set arrow etc.) and
    be executed when generating the plot,
    it would work.
    (BTW, this delayed execution is already the case without calculation).

    To me, a useful alternative would be to add an 'offset' to every element which uses coordinates, e.g.

    set label 'Hi' at first 5, graph 0.5 offset graph 0.1,0.1
    set arrow from first 3,4 offset graph -0.1,0.1 to second 5,3 offset graph 0.2,-0.1

    I am using a special graph format which currently requires quite a lot of manual, iterative adjustments of coordinates. We could discuss this topic in detail if you agree (so that my desire gets clear). I propose to do this offline, though.

     
  • Ethan Merritt

    Ethan Merritt - 2016-04-11

    set label 'Hi' at first 5, graph 0.5 offset graph 0.1,0.1

    That particular command has always been supported.

    The "set arrow" command is a different thing entirely. I think it would be very hard to support arithmetic operations A+B where A is in one coordinate system and B is in another.

     
  • Harald Harders

    Harald Harders - 2016-04-11

    I know that label has provided it for a long time. It was meant as an example.

    Why should "A+B" (or "from A offset B to C offset D") be difficult in an arrow? Basically,
    set arrow from A rto B
    does that already right now. I would expect that an arrow with "from A offset B" would start at the position where "from A rto B" ends.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.