|
From: Nunzio L. <nun...@gm...> - 2017-09-13 13:41:11
|
In fact the suggested solution allows me to insert a second plot with its
origin at some exact coordinates x,y of the first graph. What I was looking
for, instead, is placing the origin of AXES of the second graph at some
(x,y) of the previous graph. I found a solution, although cumbersome. An
example is provided here:
first functions FRAC_X and FRAC_Y are defined to find the fraction of
screen coordinates corresponding to some coordinates x and y (which seem to
refer to the axes of the last plot) as suggested in the manual of version
5.2:
# ----------------- cut here ---------------- #
GRAPH_X(X) = (X - GPVAL_X_MIN) / (GPVAL_X_MAX - GPVAL_X_MIN)
GRAPH_Y(Y) = (Y - GPVAL_Y_MIN) / (GPVAL_Y_MAX - GPVAL_Y_MIN)
SCREEN_X(X) = GPVAL_TERM_XMIN + GRAPH_X(X) * (GPVAL_TERM_XMAX -
GPVAL_TERM_XMIN)
SCREEN_Y(Y) = GPVAL_TERM_YMIN + GRAPH_Y(Y) * (GPVAL_TERM_YMAX -
GPVAL_TERM_YMIN)
FRAC_X(X) = SCREEN_X(X) * GPVAL_TERM_SCALE / GPVAL_TERM_XSIZE
FRAC_Y(Y) = SCREEN_Y(Y) * GPVAL_TERM_SCALE / GPVAL_TERM_YSIZE
# ----------------- cut here ---------------- #
here comes the script
# ----------------- cut here ---------------- #
reset
set term qt size 600,400
set size ratio -1
set encoding iso_8859_1
unset key
set xrange [-30.:30.]
set yrange [35:0]
set y2range [9.5:-0.5]
set object 1 circle center -7.25,25 size 3.355
set object 2 circle center 7.25,25 size 3.355
set ylabel 'profondit{\340} [m]'
set xlabel "distanza [m]"
set y2label 'cedimento [mm]'
set y2tics ("0" 0)
set ytics nomirror
set xtics 10
set rmargin 7
set lmargin 7
set arrow 1 from graph 0., first 0. to graph 1., first 0. nohead
set arrow 2 from graph 0., first 9. to graph 1., first 9. nohead
set arrow 3 from graph 0., first 17. to graph 1., first 17. nohead
set multiplot
plot -50.
depths = "0.0 9.0 17.0"
Ox = FRAC_X(0.)
Oy = FRAC_Y(17.)
set size noratio
set size 1,0.3
set x2zeroaxis
set y2label 'cedimento [mm]'
set y2tics nomirror 2
unset arrow 1
unset arrow 2
unset arrow 3
unset xlabel
unset ylabel
unset ytics
unset xtics
unset xlabel
unset y2label
set tmargin 0
set bmargin 0
set border 8
unset object 1
unset object 2
plot for[i=3:3] 'dis-trans-z'.word(depths,3).'-y61.6_f120.4-odd.dat' u
1:(-$6*1000.) every 2 axes x1y2 w p ls 6 lc rgbcolor "black" not
Ox1 = FRAC_X(0.)
Oy1 = FRAC_Y(0.)
Ox2 = 0.0
Oy2 = Oy - Oy1
print Ox, Oy
print Ox1, Oy1
print Ox2, Oy2
set origin Ox2,Oy2 + 0.015
# why do I have to add 0.015 here???
plot for[i=3:3] 'dis-trans-z'.word(depths,3).'-y61.6_f120.4-odd.dat' u
1:(-$6*1000.) every 2 axes x1y2 w p ls 6 lc rgbcolor "green" not
unset multiplot
# ----------------- cut here ---------------- #
the dataset can be downloaded at:
https://www.dropbox.com/s/evrqlldb1q39uum/dis-trans-z17.0-y61.6_f120.4-odd.dat?dl=0
for testing.
What really puzzles me is why I have to add 0.015 to the new origin y
screen coordinate in order to get the correct alignment!!
(The xzeroaxis of the last plot must be aligned with the horizontal line at
y=17 of the first plot)
Thanks for your help
N
2017-06-22 23:05 GMT+02:00 Nunzio Losacco <nun...@gm...>:
> Great suggestion,
>
> Thanks a lot
>
> N
>
>
> Il 22 giu 2017 9:18 PM, "theozh" <th...@gm...> ha scritto:
>
>> as far as I understand, and it looks like that gnuplot does not allow
>> other than screen coordinates for offset in the multiplot environment.
>> Probably it's not clear which coordinates it should take: the first
>> ones, the previous ones...?
>>
>> Anyway, you could use the gnuplot internal variables GPVAL_...
>> "show var GPVAL"
>> With this you need to do some "little" coordinate transformations.
>> Maybe there is even a more elegant solution?
>>
>> The following code should do what you're looking for...
>> You can actually skip all the lines starting with "print..."
>>
>>
>> ### start gnuplot example code
>> reset
>>
>> # enter the coordinates of the origin of the second plot
>> # i.e. coordinates with respect to the first plot
>> XPos = -10
>> YPos = 0
>>
>> set multiplot
>>
>> # your first plot
>> plot x
>>
>> print "TermSize x,y: ", GPVAL_TERM_XSIZE, ", ", GPVAL_TERM_YSIZE
>> print "Term X: ", GPVAL_TERM_XMIN, " to ", GPVAL_TERM_XMAX
>> print "Term Y: ", GPVAL_TERM_YMIN, " to ", GPVAL_TERM_YMAX
>> print "Graph X: ", GPVAL_X_MIN, " to ", GPVAL_X_MAX
>> print "Graph Y: ", GPVAL_Y_MIN, " to ", GPVAL_Y_MAX
>>
>> XScaling = (GPVAL_TERM_XMAX - GPVAL_TERM_XMIN)/(GPVAL_X_MAX - GPVAL_X_MIN)
>> YScaling = (GPVAL_TERM_YMAX - GPVAL_TERM_YMIN)/(GPVAL_Y_MAX - GPVAL_Y_MIN)
>> print "Scaling x,y: ", XScaling, YScaling
>>
>> XMargin = GPVAL_TERM_XMIN/XScaling
>> YMargin = GPVAL_TERM_YMIN/YScaling
>> print "Margin x,y: ", XMargin, YMargin
>>
>> XOffset = (XPos - GPVAL_X_MIN + XMargin)*XScaling/GPVAL_TERM_XSIZE
>> YOffset = (YPos - GPVAL_Y_MIN + YMargin)*YScaling/GPVAL_TERM_YSIZE
>> print "XOffset x,y: ", XOffset, YOffset
>>
>> # your second plot, for example with reduced size
>> set size 0.4
>> set origin XOffset,YOffset
>> plot x*x
>>
>> unset multiplot
>>
>> ### end gnuplot code
>>
>>
>>
>> ------------------------------------------------------------
>> ------------------
>> Check out the vibrant tech community on one of the world's most
>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>> _______________________________________________
>> gnuplot-info mailing list
>> gnu...@li...
>> Membership management via:
>> https://lists.sourceforge.net/lists/listinfo/gnuplot-info
>>
>>
|