I have got the following problem with gnuplot:
I am trying to generate a plot of several functions which is supposed to
be an eps-file and which is only allowed to have greyscale "colours". I
have the following minimal working example (see below), but in that case
the plots have the same colour but different ways of drawing the line
(i.e. a solid line vs. a dashed line) whereas I want to have two solid
lines but with different greyscale values.
Is there any way of fixing that problem?
Best wishes,
Christian
############## Minimal working example
set terminal postscript enhanced
set output "test.eps"
set style line 1 lt 1 lw 1
set style line 2 lt 2 lw 1
plot sin(x) ls 1, cos(x) ls 2
> set terminal postscript enhanced
try
set terminal postscript enhanced solid
HTH
Ingo
you might also try
set style line 1 lt 1 lw 1 lc rgb '#rrggbb'
where rr=gg=bb are the hexadecimal grey values 00, 01, 02,...,fd, fe, ff
NOTE: For some reason I've never understood the RGB values set by
linecolor (abbrv. = lc) are not converted into equivalent greyscale
values if the terminal option "monochrome" is set. Only the standard
colors are converted to monochrome, but not the manually set ones.
One of the developers here told me years ago that this behaviour was not
a bug but intended since a user would expect a rgb '#0000ff'-colored
line to be blue, not grey. However, in practice it would make much more
sense to treat the color/monochrome option as a switch that converts
everything into greyscale (there must be some fomula or table to convert
rgb into greyscale of equivalent visual brightness). I had pretty much
trouble to convert color plots into greyscale for a printed paper; I
finally gave up (to many figures to do this by hand) and asked the
editor team to do this for me...
This is the reason why you have to set rr=gg=bb for your greyscale plots
manually. A *real* color-to-monochrome switch would be a very useful
tool ;-)
Ingo
thanks, that was the solution of my problem.
Best wishes,
Chris
> thanks, that was the solution of my problem.
Please also see the current color/greyscale thread. There are simple
formulas to convert any RGB triple into a grey value. That one used by
GIMP and many digital devices is
Y = 0.299*R + 0.587*G + 0.114*B
http://en.wikipedia.org/wiki/Luma_(video)
Then just use Y,Y,Y instead of R,G,B. However, it would be nice if
Gnuplot would provide such an option for the terminal definitions if the
implementation is that easy. As a suggestion, there may be three color
options for e.g. the postscript terminal:
1. color
2. monochrome: as it is today, built-in colors set to monochrome, custom
colors defined by palette or linecolor, textcolor etc. are left as they are.
3. force-greyscale (or just greyscale); built-in colors replaced by
built-in monochrome equivalents while custom colors are translated into
greyscale values using the above or similar formula.
There has been some change on the treatment of custom colors as
described in the announcement of version 4.2.5. But it must be something
else; "monochrome" plots are still not always monochrome.
I would write a patch myself if I had more knowledge about and
experience with Gnuplot's source code (and, of course, the time to do it).
Ingo
It does not require a patch to gnuplot.
You need only add a definition in the PostScript prolog, which is there
exactly so that you can customize it locally.
I have posted this several times before, but here it is again:
%%% Uncomment the following lines to get ntsc greyscale coloring
% /ntsc { 0.114 mul exch 0.587 mul add exch 0.299 mul add } bind def
% /setrgbcolor {ntsc setgray} bind def
That applies the mapping black and white televisions used back in the
day to show a color broadcast. There's no guarantee that two random
colors will be distinguishable, but in the old days we still managed
to distinguish Lucy from Desi even though her hair wasn't red :-)
To repeat:
You can offer the choice of converting color to NTSC monochrome in
a locally-customized prolog file. There is no need to edit or rebuild
the gnuplot source.
> It does not require a patch to gnuplot.
> You need only add a definition in the PostScript prolog, which is there
> exactly so that you can customize it locally.
>
> I have posted this several times before, but here it is again:
>
> %%% Uncomment the following lines to get ntsc greyscale coloring
> % /ntsc { 0.114 mul exch 0.587 mul add exch 0.299 mul add } bind def
> % /setrgbcolor {ntsc setgray} bind def
Could you please explain, where exactly these lines have to be placed
(and uncommented)? Do you mean the file
/share/gnuplot/4.2/PostScript/prologue.ps?
Unfortunately, just adding and uncommenting the two lines (at the end of
the file) leads to errors when opening the .ps/.eps file with gv:
------------------------------------------------------------------------
Error: /undefined in defend
Operand stack:
setrgbcolor --nostringval--
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-GPL
Ghostscript 8.61: Unrecoverable error, exit code 1
- --nostringval-- 2 %stopped_push --nostringval--
--nostringval-- --nostringval-- false 1 %stopped_push 1905 1
3 %oparray_pop 1904 1 3 %oparray_pop --nostringval--
1888 1 3 %oparray_pop 1771 1 3 %oparray_pop
--nostringval-- %errorexec_pop .runexec2 --nostringval--
--nostringval-- --nostringval-- 2 %stopped_push --nostringval--
Dictionary stack:
--dict:1145/1684(ro)(G)-- --dict:0/20(G)-- --dict:76/200(L)--
--dict:174/256(L)--
Current allocation mode is local
Last OS error: 2
Current file position is 15505
------------------------------------------------------------------------
I have little experience with editing Postscript, therefore I have no
real idea what's wrong here.
> To repeat:
> You can offer the choice of converting color to NTSC monochrome in
> a locally-customized prolog file. There is no need to edit or rebuild
> the gnuplot source.
Hmm, as long as you consider gnuplot to be an expert-only application,
you may be right. However, for every-day usage by ordinary
astrophysicists and Mac users ( ;) ) a solution that works from within
gnuplot would be clearly desirable. And for Windows users it might not
even be possible to edit anything since it is all hidden in the .exe
file, as far as I remember.
Ingo
> sfeam schrieb:
>
>> It does not require a patch to gnuplot.
>> You need only add a definition in the PostScript prolog, which is there
>> exactly so that you can customize it locally.
>>
>> I have posted this several times before, but here it is again:
>>
>> %%% Uncomment the following lines to get ntsc greyscale coloring
>> % /ntsc { 0.114 mul exch 0.587 mul add exch 0.299 mul add } bind def
>> % /setrgbcolor {ntsc setgray} bind def
>
> Could you please explain, where exactly these lines have to be placed
> (and uncommented)? Do you mean the file
> /share/gnuplot/4.2/PostScript/prologue.ps?
Yes, that is the correct file.
You can add the new lines at the very top of the file.
To "uncomment" the lines, remove a single % from the front of each one.
Ethan
> Yes, that is the correct file.
> You can add the new lines at the very top of the file.
Correction: I *must* place it at top, otherwise I get either errors (see
below) or nothing happens.
However, this solution is quite unsatisfactory since it requires editing
a central file as well as some "expert knowledge". And, of course, it
is far from being an "every day" solution (many users wouldn't even
remember how to do it after the next Gnuplot update has erased the lines
you posted - I didn't find them anywhere else, not even with Google).
Much better would by any solution that may be controlled from the
plotting script without the need to hack Gnuplot sytem files.
I am still convinced that the best solution would be to make the
monochrome option convert all colory, even user-defined ones, into
grayscales, since this is would a user would normally expects (I have
asked colleagues and there was nobody who didn't shake head about the
current behaviour of keeping user-defined colors if monochrome is set).
I can hardly imagine any situation where monochrome standard styles and
user-defined colors not being grayscaled would be desired by the user.
Thanks anyway.
Ingo
> sfeam schrieb:
>
>> Yes, that is the correct file.
>> You can add the new lines at the very top of the file.
>
> Correction: I *must* place it at top, otherwise I get either errors (see
> below) or nothing happens.
>
> However, this solution is quite unsatisfactory since it requires editing
> a central file as well as some "expert knowledge".
You do not have to use the central file. The whole idea is to make it
easy to change to a different prologue. The command you are looking
for is "set loadpath". See also "help postscript prolog".
Note that this mechanism can also used to change the default set of
colors, which may in fact be exactly what you really want to do.
You could also change or add point symbols to the default set.
> And, of course, it
> is far from being an "every day" solution (many users wouldn't even
> remember how to do it after the next Gnuplot update has erased the lines
> you posted - I didn't find them anywhere else, not even with Google).
>
> Much better would by any solution that may be controlled from the
> plotting script without the need to hack Gnuplot sytem files.
IMHO you have this exactly backwards. It offers users the ability to
customize their local PostScript preferences without requiring them to
edit and rebuild the whole gnuplot package. It also allows different
users on the same machine to have different preferences, or even the
same user to swap between different customized prologue files.
> I am still convinced that the best solution would be to make the
> monochrome option convert all colory, even user-defined ones, into
> grayscales, since this is would a user would normally expects (I have
> asked colleagues and there was nobody who didn't shake head about the
> current behaviour of keeping user-defined colors if monochrome is set).
Think of it this way:
When you say "set term post 'Helvetica,10'", it sets the default
font to 10 pt Helvetica. But it doesn't prevent you from changing the
font face or size in specific labels.
Similarly if you say "set term post pointsize 2", it doubles the default
size of the point symbols. But it does not prevent you from explicitly
using point symbols of some other size.
The 'set term post monochrome' option works exactly the same way.
It selects a default set of line types that use only black ink, and a
default palette that gives you a pure greyscale. But it does not prevent
you from explicitly drawing custom-colored lines _if you choose to do so_.
> I can hardly imagine any situation where monochrome standard styles and
> user-defined colors not being grayscaled would be desired by the user.
If you don't want to use custom colors, then don't use custom colors.
Stick with the default line types and palette, and you can even toggle
the color/monochrome defaults by editing the output PostScript file [*].
You can still define your own line styles, so long as you do so using
the default set of color values (lt 1, lt 2, ...) that the program
already knows about.
It is unreasonable to explicitly define and request customized colors
and then complain when the program does exactly what you asked it to.
[*] The postscript files produced by gnuplot contain a section near the
top that contains lines as shown below. By changing "/Color true" to
"/Color false", you can accomplish the same thing as the "set term post
mono" command line option. That is, the default line types will switch
from black to color. For example, "linetype 3" will be drawn in blue.
But it only affects the _default_ line types. If you explicitly issue
a command that defines a special color, then you get what you ask for.
%
% The following true/false flags may be edited by hand if desired.
% The unit line width and grayscale image gamma correction may also be
changed.
%
/Color true def
/Blacktext false def
/Solid true def
/Dashlength 1 def
/Landscape true def
/Level1 false def
/Rounded false def
> You do not have to use the central file. The whole idea is to make it
> easy to change to a different prologue. The command you are looking
> for is "set loadpath". See also "help postscript prolog".
Hmm, I understand it this way that one has to state
set loadpath "$MY_LOCAL_PATH"
where $MY_LOCAL_PATH is the path of a folder that contains customized
files, e.g. ~/gnuplotparams. I did this and copied prologue.ps into it,
edited it - but nothing happened.
How can I explicitely load the edited prologue file? I cannot find any
useful instruction here. Something like "load
'~/gnuplotparams/myprologue.ps" obviously fails since gnuplot expects
gnuplot commands, not postscript commands.
> When you say "set term post 'Helvetica,10'", it sets the default
> font to 10 pt Helvetica. But it doesn't prevent you from changing the
> font face or size in specific labels.
>
> Similarly if you say "set term post pointsize 2", it doubles the default
> size of the point symbols. But it does not prevent you from explicitly
> using point symbols of some other size.
Concerning the colors the natural way of thinking is the same as with
photography: At first you choose a film (color or b/w) resp. a color/bw
mode on a digital camera. This corresponds to the "set terminal"
options. Then you choose an object or scenery you want to photograph,
and arrange proper lighting etc.. This corresponts to the style
settings. Sometimes you might also alter the colors of your object, e.g.
by applying make-up to a model. This corresponds to "linecolor" etc.
But manually modifying the colored appearance of the object will never
make a b/w film show these parts colored with everything monochrome, and
no photographer would ever expect this behaviour. One will have to
explicitely edit an image to get such effects (like the girl in red in
"Schindler's List"). But what the user (at least all people I have asked
about) would naturally excpect is "monochrome" acting as a b/w film
(option) in a (digital) camera.
For fonts it is a bit different: There it is common to choose a font and
a standard size at first and then, where needed, change to \large,
\footnotesize or whatever. Fonts are generally treated different by most
users than colors.
> The 'set term post monochrome' option works exactly the same way.
> It selects a default set of line types that use only black ink, and a
> default palette that gives you a pure greyscale. But it does not prevent
> you from explicitly drawing custom-colored lines _if you choose to do so_.
As already said: All people I have asked about do not choose colored
lines in monochrome surroundings but they choose a linecolor that should
appear as RGB, for the "color" option, but being transformed to a
grayscale for the "monochrome" option. Just as a b/w film does.
> It is unreasonable to explicitly define and request customized colors
> and then complain when the program does exactly what you asked it to.
I cannot agree. IMHO it is by far more unreasonable to expect green
graffitti (=custom color) on a red brick wall (=default colors) to
appear as green on a grey background in a b/w photo. At least for, let's
say, 99% of all users. OK, it might be a bit different for the 'digital
generation' who is also complaining about life not having a "resume from
saved game" option ;-)
Ingo
The way you described for grayscale plots will only work for Postscript.
But are there other ways for other terminals (except for the ugly method
of manually changing every color in the gp script), e.g. for PNG, PDF or
even X11, windows or Aqua?
Ingo
That's it -- the monochrome/color option is for postscript only. Appropriate
tools should be used to adjust/change colours of drawn figures (in other
formats). There is e.g. psmono device of ghostscript or an option of
convert.
If you wish to have a colour plot which well prints on a black&white
printer, than you can use the "color printable on gray
(black-blue-violet-yellow-white)" palette, see
help palette rgb
---
PM
> That's it -- the monochrome/color option is for postscript only. Appropriate
> tools should be used to adjust/change colours of drawn figures (in other
> formats). There is e.g. psmono device of ghostscript or an option of
> convert.
A global color/mono switch that uses an appropriate (and
user-adjustable) conversion function/weighting would be nice.
At least for palettes based on external files and user-defined functions
one can do this in a gnuplot script. For linecolor and textcolor
statements as well as for "set palette defined" one has to do this
manually, unfortunately.
I am now thinking of writing an external program as a palette editor in
which one can define the luminance (using e.g. 0.3R+0.6G+0.1B) and the
color (r-b-g on a relative scale) hue independently, but this may take
longer and is independent from the color/gray switch issue.
> If you wish to have a colour plot which well prints on a black&white
> printer, than you can use the "color printable on gray
> (black-blue-violet-yellow-white)" palette, see
I've seen it, but I wouldn't say that that palette is well-suited for
printing. For a b/w-only plot a simple grayscale may be better; but
sometimes one wishes to create a palette that is useful for both color
and b/w display/printing, which can be essential for scientific papers
which should appear in a color online version as well as a b/w printed
version (in most journals you must pay an extra fee for color prints).
For such issues I have written a gnuplot script that allows a
gamma-corrected transformation of file and function palettes. The
built-in functions can be found with show palette rgbformulae.
Translation into a gnuplot-readable format is straightforward (replace
360 by 2pi, |*| by abs(*), and note that function 32 changes its
direction once it hits the gray value 1 or 0).
But again, this cannot be used for plot scripts with many linestiles
with custom colors. Maybe the best method would be to provide
independent scripts for the linestyles included with the "load" command,
one for color, one for b/w, and then simply comment/uncomment the "load"
lines.
Ingo