Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Horizontal colorbox: Change the tic labels direction

1,545 views
Skip to first unread message

Ingo Thies

unread,
Nov 27, 2010, 1:03:57 PM11/27/10
to
Dear all,

in addition to my (still yet unanswered) question how to toggle clipping
off for the clabel, I would like to ask whether/how one could change the
placement of the colorbox tic labels (the numbers) and the clabel.
Currently, after some update last year, they are placed *between* the
colorbox and the graph, when horiz orientation is used. The normal way
should be that graph and label are on opposite sides of the colorbox
(see the poster I linked to in my previous question), i.e. label below
colorbox if colorbox is below graph.

I could not reproduce when this behaviour changed (maybe there was an
old gnuplot version installed when I plotted the graph, where this still
worked), but it would be nice to have horizontal colorboxes working
properly again.

Ingo

sfeam

unread,
Nov 27, 2010, 2:33:21 PM11/27/10
to
Ingo Thies wrote:

> Dear all,
>
> in addition to my (still yet unanswered) question how to toggle
> clipping off for the clabel, I would like to ask whether/how one could
> change the placement of the colorbox tic labels (the numbers) and the
> clabel. Currently, after some update last year, they are placed
> *between* the colorbox and the graph, when horiz orientation is used.

I don't see this behaviour in any version of gnuplot that I have tried,
including 4.2.5, 4.4.2 (current) and 4.5 (cvs).

My test uses the following command to place the colorbox below the plot
set colorbox user origin graph 0,-.2 size graph 1,.05

I do not see any unexpected clipping, and the colorbox tic labels
appear underneath the box. However, these tests used the default
margins.

When I set the margins to
set bmargin at screen 0; set tmargin at screen 1
set lmargin at screen 0; set rmargin at screen 1

I still see no unexpected clipping in the PostScript output from gnuplot.
I do see that the placement of the colorbox tic labels "bottoms out"
at the original bmargin, but this hasn't changed between 4.2.5 and
today's CVS. So I can't pin down the where or when of any change to
the code that would cause the difference you report.

> I could not reproduce when this behaviour changed (maybe there was an
> old gnuplot version installed when I plotted the graph, where this
> still worked), but it would be nice to have horizontal colorboxes
> working properly again.

The basic issue seems to be what happens when you deliberately place
things outside of the margins. Gnuplot has never consistently supported
drawing outside the margins. Before version 4.4 it was terminal-dependent
whether you would get wrap-around, nothing, an extended plot, or a
program crash. Prior to release of version 4.4 most terminals were
modified to explicitly ignore attempts to draw outside of the margins.

PostScript was a major exception; since drawing outside the margins of
a PostScript plot was never a source of program crashes or corrupted plots,
we just left it alone. We did add a warning in the documentation and
release notes to explain this and to advise that such plots might not
work in PostScript either in some future version, since no one is testing
designing or testing new code with this in mind.

My best suggestion is not to draw outside the margins, although I
realize this would require you to modify some post-processing script.

For the moment I think the quickest work-around is to edit the final
PostScript output file to change the y-coordinate of the colorbox
tic labels - either manually in a text editor or using a GUI like
scribus that lets you select and drag the tic labels to a new place.
I just tested this using scribus version 1.3.6 and it only took a
moment to translate the colorbox labels to the currect place.

Ethan


>
> Ingo

Ingo Thies

unread,
Nov 27, 2010, 3:04:21 PM11/27/10
to
Am 2010-11-27 20:33, schrieb sfeam:
> Ingo Thies wrote:
>
>> Dear all,
>>
>> in addition to my (still yet unanswered) question how to toggle
>> clipping off for the clabel, I would like to ask whether/how one could
>> change the placement of the colorbox tic labels (the numbers) and the
>> clabel. Currently, after some update last year, they are placed
>> *between* the colorbox and the graph, when horiz orientation is used.
>
> I don't see this behaviour in any version of gnuplot that I have tried,
> including 4.2.5, 4.4.2 (current) and 4.5 (cvs).
>
> My test uses the following command to place the colorbox below the plot
> set colorbox user origin graph 0,-.2 size graph 1,.05
>
> I do not see any unexpected clipping, and the colorbox tic labels
> appear underneath the box. However, these tests used the default
> margins.

Please use the following test script from my posting "Rigid
behaviour..." from yesterday:

reset
set term push
set isosamples 100,100 #
set xrange [-2:2];set yrange [-2:2]
f(x,y)=1./sqrt(2.*pi)*exp(-0.5*(x*x+y*y))
set table 'test.tmp'
splot f(x,y)
unset table
set term postscript eps color size 12cm,12cm
set output 'test.eps'
#set format x "";set format y ""
set size ratio -1
set tmargin 0
set bmargin 0
set lmargin 0
set rmargin 0
set border front lc rgb '#aaaaaa'
set multiplot layout 2,2
unset colorbox
plot 'test.tmp' using 1:2:3 notitle with image#;unset object 1
plot 'test.tmp' using 1:2:3 notitle with image
plot 'test.tmp' using 1:2:3 notitle with image
set cblabel "Colorlabel" offset 0.0,0.0#
## Please note that the colorbox is placed *below*,
## not inside the BoundingBox!
set colorbox horiz user origin 0.,-0.06 size 1.,0.04
plot 'test.tmp' using 1:2:3 notitle with image
unset multiplot
set term pop

The crucial point is that the computer-generated script requires the
labels to be drawn *outside* the postscript bounding box. Although
noclip should be set as default (and even when I set it explicitely) the
cblabel is clipped to the BB border.

Changing the code that generates the script (as well as the image data
file) would require major work in that code due to some
cross-dependencies I would have to dig out again. As long there is no
safe way to estimate the required space I would prefer to write outside
the BB and let fixbb do the rest.

Since I created the poster recently (the conference was in mid October)
this clipping behaviour wasn't present recently. However, the current
gnuplot 4.4.2 does show this behaviour.

> PostScript was a major exception; since drawing outside the margins of
> a PostScript plot was never a source of program crashes or corrupted plots,
> we just left it alone. We did add a warning in the documentation and
> release notes to explain this and to advise that such plots might not
> work in PostScript either in some future version, since no one is testing
> designing or testing new code with this in mind.
>
> My best suggestion is not to draw outside the margins, although I
> realize this would require you to modify some post-processing script.

Do you remember any piece of code where this clipping has been
introduced to the code? I guess that there should be some deliberately
added case check that changes any out-of-BB coordinates to the BB border
(the same way as the meanwhile removed mousing angle limitation to
+/-180 degrees), but I didn't find it so far.

The point why I do not want to change this post-processing script is
that using the canvas for easy scaling of the sub-plots is so far
extremely robust. Any attempt to scale them with non-zero margins is
extremely sensitive to any labels present; one has to take care that
everything is inside the canvas, so one has to estimate the size of the
labels etc.

Simply allowing to write outside the BB/canvas without any deliberate
restrictions/clippings would, from my point of view, the cleanest way.

As far as I understand the BB in postscript is just an advice to the
displaying/printing tool but does not have any consequences for the
content itself. So I do not see the point why there should be such a
check in gnuplot.

> For the moment I think the quickest work-around is to edit the final
> PostScript output file to change the y-coordinate of the colorbox
> tic labels - either manually in a text editor or using a GUI like
> scribus that lets you select and drag the tic labels to a new place.

I would prefer an automatic correction. Or, even better, no clipping at all.

Another possibility, I could think of, would be an enhanced layout
option for multiplot that allows to explicitely specify the plot
consisting of n x m subframes, each with a given aspect ratio q (=1 in
case of square frames).

Ingo

sfeam

unread,
Nov 27, 2010, 5:41:30 PM11/27/10
to
Ingo Thies wrote:
> Please use the following test script from my posting "Rigid
> behaviour..." from yesterday:

[snip]

> The crucial point is that the computer-generated script requires the
> labels to be drawn *outside* the postscript bounding box. Although
> noclip should be set as default (and even when I set it explicitely)
> the cblabel is clipped to the BB border.

You are not using the word "clip" as I normally understand it,
but I do get what you mean; the vertical coordinate of the
colorbox label and xtics text has been limited to 0 rather than
allowing it to go negative.

> Since I created the poster recently (the conference was in mid
> October) this clipping behaviour wasn't present recently. However, the
> current gnuplot 4.4.2 does show this behaviour.

I get essentially identical output from your test script using
gnuplot versions 4.2.0, 4.2.5, 4.4.0, 4.4.2, and current CVS.
So nothing has changed since at least 2007.

> Do you remember any piece of code where this clipping has been
> introduced to the code? I guess that there should be some deliberately
> added case check that changes any out-of-BB coordinates to the BB
> border (the same way as the meanwhile removed mousing angle limitation
> to +/-180 degrees), but I didn't find it so far.

There was no recent change.



> The point why I do not want to change this post-processing script is
> that using the canvas for easy scaling of the sub-plots is so far
> extremely robust. Any attempt to scale them with non-zero margins is
> extremely sensitive to any labels present; one has to take care that
> everything is inside the canvas, so one has to estimate the size of
> the labels etc.

Aha. This much I can help with right now. Your current script
uses the commands below to set the margins:


> set tmargin 0; set bmargin 0; set lmargin 0; set rmargin 0

As you note, this method is not robust.
Instead you should use the commands


set bmargin at screen 0; set tmargin at screen 1
set lmargin at screen 0; set rmargin at screen 1

This fixes the plot borders at an absolute position relative to the
canvas. They do not change as a result of labels, etc. You can,
of course, specify values other than 0.0/1.0 if you don't want the
adjacent plots to touch each other.
See
http://gnuplot.sourceforge.net/demo/margins.html

> As far as I understand the BB in postscript is just an advice to the
> displaying/printing tool but does not have any consequences for the
> content itself.

Correct.

> So I do not see the point why there should be such a
> check in gnuplot.

Huh? Gnuplot writes a bounding box record corresponding to the
"size" keyword in the "set term postscript" command. You can easily
edit this to anything you like. Gnuplot does not make any further
checks against these values; it just writes them to the output file.

As I understand it, your problem really has nothing at all to do
with the PostScript bounding box. It has to do with the gnuplot
margin settings. The same problem would be there no matter what
the bounding box is set to.

> Another possibility, I could think of, would be an enhanced layout
> option for multiplot that allows to explicitely specify the plot
> consisting of n x m subframes, each with a given aspect ratio q (=1 in
> case of square frames).

Isn't that what your script is already doing?
> set multiplot layout 2,2
> set size ratio -1

> Simply allowing to write outside the BB/canvas without any deliberate
> restrictions/clippings would, from my point of view, the cleanest way.

I understand. But even if we can figure out why the code seems to treat
colorbox labels differently (which I don't currently have any ideas about)
that won't provide an immediate fix for you. I was hoping that you
could solve the problem immediately with no change to the program if you
use a different set of commands to set the margins.

Ethan

sfeam

unread,
Nov 27, 2010, 8:31:32 PM11/27/10
to
sfeam wrote:
>> Do you remember any piece of code where this clipping has been
>> introduced to the code? I guess that there should be some
>> deliberately added case check that changes any out-of-BB coordinates
>> to the BB border (the same way as the meanwhile removed mousing angle
>> limitation to +/-180 degrees), but I didn't find it so far.
>
> There was no recent change.

The code in question turns out to be in color.c at lines 676ff and 695ff.

27-Aug-2002
Commit message: Use signed int for cblabel positioning.

http://gnuplot.cvs.sourceforge.net/viewvc/gnuplot/gnuplot/src/color.c?r1=1.35&r2=1.36

So every version since 3.7.2 has behaved this way.
I do not know what will break if the limit is removed.

Ethan

Ingo Thies

unread,
Nov 28, 2010, 4:09:04 AM11/28/10
to
Am 2010-11-27 23:41, schrieb sfeam:

> I get essentially identical output from your test script using
> gnuplot versions 4.2.0, 4.2.5, 4.4.0, 4.4.2, and current CVS.
> So nothing has changed since at least 2007.

Hmm, this is strange. Then I wonder how how I could create the
multiplots in my poster (I know for sure that I didn't edit the eps file
except for applying fixbb). This poster should be the best available
proof that it definitively *had* worked some day before 17th October
this year ;-)

Maybe there was one of the CVS versions within some weeks/months before
the conference where it worked by chance.

Even stranger, it works properly with vertical colorboxes and the label
to the right. Just tested by changing the color box line to

set colorbox vert user origin 1.06,0. size 0.04,1.

> Aha. This much I can help with right now. Your current script
> uses the commands below to set the margins:
>> set tmargin 0; set bmargin 0; set lmargin 0; set rmargin 0
> As you note, this method is not robust.
> Instead you should use the commands
> set bmargin at screen 0; set tmargin at screen 1
> set lmargin at screen 0; set rmargin at screen 1

This does not work either. Even if I use proper partition (i.e. set the
margins individually this way for each subplot; otherwise one gets all
plots in the same frame), the result is apparently the same. And again,
only the horizontal colorbox below is affected, not the vertical one to
the right. If the horizontal cb would behave the same way as the
vertical one, I would be happy ;-)

>> Another possibility, I could think of, would be an enhanced layout
>> option for multiplot that allows to explicitely specify the plot
>> consisting of n x m subframes, each with a given aspect ratio q (=1 in
>> case of square frames).
>
> Isn't that what your script is already doing?

No, my script uses the canvas itself. However, I am currently developing
a helper script that allows to specify a "plotting canvas" like this:

First you specify how large the plotting area should be (e.g.
15cmx10cm), how many subplots (e.g. 3x2) and the aspect ratio of each
subplot (1, i.e. square-shaped in this example). Then, you specify the
fractions of the *total* (yet unspecified) canvas to be dedicated to the
margins (e.g. 0 left, right and top, 0.2 bottom margin).

Then the script calculates the absolute margin settings (using the
syntax you recommended) and the total canvas. After calling this script,
you set the terminal with the size given by the variables from the
script, i.e. size xcanvas cm, ycanvas cm (the unit is not fixed, only
the numbers are given). Furthermore, an additional frames script will
place the axis labels centered below/to the left of the whole panel
(assuming that all subframes have the same units, which is up to the user).

For now, it seems to work (some bugs may still, but has yet to be
implemented to the SPH plotting code. But this should hopefully easy
since I probably will only have to create some load <scriptfile> lines
and remove the existing margins and labels specifications. If it works
stable it would propaply the cleanest workaround since it secures
plotting within the canvas as well as the correct layout of the subplots.

However, an open task is the estimation of the required space for the
labels. Maybe I can find some handsome rule-of-the-thumb formula for
axis and colorbox labels. Meanwhile it is still a matter of trial and error.

When it is release-ready, I can post it here. An earlier version I had
recently posted to someone, maybe I can find that post.

But thanks so far.

Ingo

Ingo Thies

unread,
Nov 29, 2010, 1:45:00 PM11/29/10
to
Am 2010-11-28 10:09, schrieb Ingo Thies:

> When it is release-ready, I can post it here. An earlier version I had
> recently posted to someone, maybe I can find that post.

It was my reply to a posting on 2010-08-18, subject "multiplot size and
turning off labels"

Here is an updated version. There are two scripts, the first named
"mplayout_base.gp", the second "mpayout_frame.gp". First, the base file
(to be called before the terminal definition). It outputs some variables
(e.g. margin setting functions) and the canvas size. Input to be
provided are the "plotting canvas" (i.e. the graph panel without
margins), the number of columns and rows, and the aspect ratio of the
subframes (e.g. 1.0 for square frames).

------------------------------------------------------
#### Helper functions for proper multiplotting
#### Define before call:
## Plotting canvas (i.e. without tics, labels, titles etc.)
# Examples
# xpcanv= 12. #plotting canvas size x
# ypcanv= 12. #plotting canvas size y
# ncols =1 # number of columns
# nrows =3 # number of rows
# qratio=1.0 # desired aspect ratio y/x
## Overall margins (example):
#lmgtot=0.07; rmgtot=0.03
#tmgtot=0.01; bmgtot=0.09
#
## Usage:
# 1. Define above variables (either in or before calling this script)
# 2. Call this script
# 3. set terminal ...
# 4. set multiplot
# 5. do the plots; call mplayout_frame.gp before each plot!
## Setting the margins via "set *margin screen *mg", * = l,r,t,b
# lmg=flmg(c); rmg=frmg(c); bmg=fbmg(r); rmt=ftmg(r)
########################################################################
## Overall borders from margins
lborder=lmgtot; rborder=1.-rmgtot
tborder=1.-tmgtot; bborder=bmgtot
## Calculate frame dimensions and recommended canvas dimensions
# graph dims in canvas units:
wgraph=rborder-lborder; hgraph=tborder-bborder
# graph pseudo aspect ratio (i.e. in canvas units):
qgraph=hgraph/wgraph
# scaled plot frame width and height in canvas units
wframe=wgraph/ncols; hframe=hgraph/nrows
# scaled plot aspect ratio for frame for square unit canvas
# qframe = hgraph/nrows/wgraph*ncols = hgraph/wgraph * ncols/nrows
# = qgraph/qnumber
qframe=hframe/wframe
# plotting canvas aspect ratio; not yet used
qgreal=(qratio*nrows)/ncols
# Canvas aspect ratio qcreal = qratio/qframe
# = qratio/qgraph*nrows/ncols = qgreal/qgraph
qcreal=qratio/qframe
## Full canvas dimensions from plotting canvas dimensions
xcanvas=xpcanv/wgraph
ycanvas=ypcanv/hgraph
print 'wgraph = ',wgraph
print 'hgraph = ',hgraph
print 'wframe = ',wframe
print 'hframe = ',hframe
print 'qgraph = ',qgraph
print 'qframe = ',qframe
print 'qgreal = ',qgreal
print 'Recommended canvas aspect ratio:'
print 'qcreal = ',qcreal
print 'Recommended canvas dimensions:'
print 'canvas= ',xcanvas,' x ',ycanvas
#### Subframe border functions
## count cols from left
flmg(c)=lmgtot+(c-1)*wframe
frmg(c)=lmgtot+c*wframe
## count rows from top
fbmg(r)=bmgtot+(nrows-r)*hframe
ftmg(r)=bmgtot+(nrows-r+1)*hframe
## Label placement (to be tested)
x1loff=0.5*(ncols-1); x2loff=0.
y1loff=1.0; y2loff=0.5*(nrows-1)
------------------------------------------------------

Then, before each plot in in the multiplot environment, the following
script has to be called, given the current column c and row r (counted
from the left/top; in contrast to the absolute margins which are
measured from the bottom):

------------------------------------------------------
#### Helper script for mplayout_base.gp
#### To be placed before each plot
##
## Define before each call:
## x1loff, x2loff - x label offsets (global)
## y1loff, y2loff - y label offsets (global)
## Example:
## x1loff=0.5*(ncols-1); x2loff=0.
## y1loff=1.0; y2loff=0.5*(nrows-1)
## (this is the default definition in mplayout_base.gp
## c,r - current column, row number (before each plot)
## c=1...ncols (left to right)
## r=1...nrows (top to bottom)
## Define before multiplot (or set the axis labels manually):
## flgxlabel - >0: use xlabel
## flgylabel - >0: use ylabel
## xlabeltext - text string for xlabel
## ylabeltext - text string for ylabel
################################################################################
## Define margins
lmg=flmg(c); rmg=frmg(c); bmg=fbmg(r); tmg=ftmg(r)
## Print margins
print 'lmg, rmg, tmg, rmg = ',lmg, rmg, tmg, rmg
## set margins in gnuplot using the absolute marginssyntax
set lmargin screen lmg
set rmargin screen rmg
set bmargin screen bmg
set tmargin screen tmg
## set/unset xylabels
unset xlabel; unset ylabel; set format x ''; set format y ''
#
## The following two if(...) statements place axis labels
## at the outer boundaries while suppressing them between
## neighbouring frames.
## (Sorry for linebreak in this posting)
if (r==nrows&&c==1&&flgxlabel>0) set xlabel xlabeltext offset graph
x1loff, x2loff
if (r==nrows&&c==1&&flgylabel>0) set ylabel ylabeltext offset
y1loff,graph y2loff
## Similarly, toggle tic labels
if (r==nrows&&flgxticlabels) set format x '%g'
if (c==1&&flgyticlabels) set format y '%g'
if (r==nrows) print 'using xtics labels at r,c =',r,c
------------------------------------------------------

Place all these files, including the following demo script, in the same
folder. The demo produces an output file test.eps with a 2x2 Gaussian
color map (four times the same plot, so it may look a bit boring,
sorry). Run the demo script with gnuplot, the helper files are
automatically loaded there.

------------------------------------------------------
reset
set term push

#### Generate test data file test.tmp
set isosamples 100,100 #
w=2.; dw=0.5; ndw=5
set xrange [-w:w]; set yrange [-w:w]
set xtics dw; set mxtics ndw; set ytics dw; set mytics ndw
set cbrange [0:0.4]
set cbtics 0.05; set mcbtics 5


f(x,y)=1./sqrt(2.*pi)*exp(-0.5*(x*x+y*y))
set table 'test.tmp'
splot f(x,y)
unset table

#### Graph shape
xpcanv= 12. #plotting canvas size x
ypcanv= 12. #plotting canvas size y
## Graph partition
ncols =2 # number of columns
nrows =2 # number of rows
## Frame shape
qratio=1. # desired aspect ratio y/x
## Overall margins (some examples)
#lmgtot=0.; rmgtot=0.; tmgtot=0.; bmgtot=0.
#lmgtot=0.09; rmgtot=0.01; tmgtot=0.01; bmgtot=0.19
lmgtot=0.10; rmgtot=0.17; tmgtot=0.01; bmgtot=0.09
## xlabeltext, ylabeltext
load 'mplayout_base.gp'

#### Terminal definitions
#set term postscript eps enhanced color size 12cm,12cm
#set term postscript eps enhanced color noclip size 12cm,12cm
set term postscript eps enhanced color noclip size xcanvas cm, ycanvas
cm font "Helvetica,24"
set output 'test.eps'
#set object 1 rectangle from screen 0,0 to screen 1,1 behind fc rgb
"black" fs solid
#### Labels and formats


set format x ""; set format y ""

unset xlabel; unset ylabel; unset cblabel
set size ratio -1
set border front lc rgb '#000000'; set tics in front
unset colorbox
#xlabeltext="x"; ylabeltext="y"
xlabeltext="{/Symbol f}"; ylabeltext="{/Symbol q}"
flgxlabel=1; flgxticlabels=1
flgylabel=1; flgyticlabels=1
#######
set multiplot# layout 2,2 #(the layout option is no longer needed here)
## Plot 1
c=1;r=1
load 'mplayout_frame.gp'


plot 'test.tmp' using 1:2:3 notitle with image#;unset object 1

## Plot 2
c=2;r=1
load 'mplayout_frame.gp'


plot 'test.tmp' using 1:2:3 notitle with image

## Plot 3
c=1;r=2
load 'mplayout_frame.gp'


plot 'test.tmp' using 1:2:3 notitle with image

## Plot 4
c=2;r=2
load 'mplayout_frame.gp'
set cblabel "Colorlabel" offset 0.0,0.0
set colorbox vert user origin 1.-rmgtot+0.02,bmgtot size 0.04,hgraph
show xlabel; show ylabel


plot 'test.tmp' using 1:2:3 notitle with image
unset multiplot
set term pop

------------------------------------------------------

Again sorry for some lines broken in this posting. Please make sure to
fix all linebreaks before using with gnuplot.

Any helpful comments are welcome!

Ingo

0 new messages