|
From: Benjamin L. <lin...@gm...> - 2009-08-31 18:26:32
|
Hello list,
I came across a (for me) strange behaviour, which is, that if you use
the "labels" plotstyle increases the linestyle, although no line is drawn.
I am using a 4.3.0 CVS snapshot version.
Test case:
set style data linespoints
set style line 1 lt 1 lc rgb "red"
set style line 2 lt 1 lc rgb "green"
set style line 3 lt 1 lc rgb "blue"
set label 1 "lines should be red and green" at graph 0.5, 0.9
set style increment user
plot '-' u 0:1, '-' u 0:1:1 with labels offset character 0,1,0 , '-' u 0:1
1
2
3
4
5
e
1
2
3
4
5
e
2
3
4
5
6
e
I would expect the lines to have color red and green, not red and blue.
I looked at the source code in src/plot2d.c and found that for certain
plotstyles this increase of the line style is disabled. However, not for
the "labels" plotstyle.
Is this deliberate?
May I suggest the following change:
diff -r d67b4d3fbb86 src/plot2d.c
--- a/src/plot2d.c Mon Aug 31 09:08:58 2009 +0200
+++ b/src/plot2d.c Mon Aug 31 09:09:17 2009 +0200
@@ -1975,8 +1975,9 @@
&& this_plot->plot_style != IMAGE
&& this_plot->plot_style != RGBIMAGE
&& this_plot->plot_style != RGBA_IMAGE
+ && this_plot->plot_style != LABELPOINTS
/* don't increment the default line/point properties if
- * this_plot is an image */
+ * this_plot is an image or labels plot */
) {
if (this_plot->plot_style & PLOT_STYLE_HAS_POINT)
++point_num;
benjamin
|
|
From: Ethan M. <merritt@u.washington.edu> - 2009-08-31 19:36:46
|
On Monday 31 August 2009 11:26:16 Benjamin Lindner wrote:
> Hello list,
>
> I came across a (for me) strange behaviour, which is, that if you use
> the "labels" plotstyle increases the linestyle, although no line is drawn.
That is entirely expected, but only if you realize that "linestyle" and
"linetype" have evolved into misnomers. The linestyle or linetype is
described by a structure that specifies far more than just the color.
From term_api.h:
typedef struct lp_style_type { /* contains all Line and Point properties */
int pointflag; /* 0 if points not used, otherwise 1 */
int l_type;
int p_type;
int p_interval; /* Every Nth point in style LINESPOINTS */
double l_width;
double p_size;
TBOOLEAN use_palette;
struct t_colorspec pm3d_color;
/* ... more to come ? */
} lp_style_type;
The thing is, these properties affect points just as much as they affect
lines per se. You still have to draw the point with some linewidth and
some color, right? For that matter, what about plots "with linespoints"
where the same set of properties applies to both the lines and the points.
Which brings us to labels...
One of the properties of a label is {{no}point}, which controls whether or
not a point is drawn exactly at the coordinates given. If you select to
have a point drawn for each label, the point properties have to come from
somewhere and the obvious place is to take them from the "linestyle" of the
current plot.
So, for example, you might draw a plot containing many labeled data sets,
and distinguish which point is from which dataset by the color/shape of the
associated points. Make sense?
set style data labels
plot '1.dat' point pt 5, '2.dat' point pt 7, '3.dat' point pt 1
That will give you a plot containing three sets of labeled points.
All the labels will be in the normal (black) font since we haven't done
anything special to do otherwise. Some will be marked by red squares,
some by green circles, and some by blue crosses.
> I am using a 4.3.0 CVS snapshot version.
>
> Test case:
> set style data linespoints
>
> set style line 1 lt 1 lc rgb "red"
> set style line 2 lt 1 lc rgb "green"
> set style line 3 lt 1 lc rgb "blue"
>
> set label 1 "lines should be red and green" at graph 0.5, 0.9
>
> set style increment user
>
> plot '-' u 0:1, '-' u 0:1:1 with labels offset character 0,1,0 , '-' u 0:1
> 1
> 2
> 3
> 4
> 5
> e
> 1
> 2
> 3
> 4
> 5
> e
> 2
> 3
> 4
> 5
> 6
> e
>
> I would expect the lines to have color red and green, not red and blue.
>
> I looked at the source code in src/plot2d.c and found that for certain
> plotstyles this increase of the line style is disabled. However, not for
> the "labels" plotstyle.
> Is this deliberate?
> May I suggest the following change:
>
> diff -r d67b4d3fbb86 src/plot2d.c
> --- a/src/plot2d.c Mon Aug 31 09:08:58 2009 +0200
> +++ b/src/plot2d.c Mon Aug 31 09:09:17 2009 +0200
> @@ -1975,8 +1975,9 @@
> && this_plot->plot_style != IMAGE
> && this_plot->plot_style != RGBIMAGE
> && this_plot->plot_style != RGBA_IMAGE
> + && this_plot->plot_style != LABELPOINTS
> /* don't increment the default line/point properties if
> - * this_plot is an image */
> + * this_plot is an image or labels plot */
> ) {
> if (this_plot->plot_style & PLOT_STYLE_HAS_POINT)
> ++point_num;
>
>
> benjamin
--
Ethan A Merritt
Biomolecular Structure Center
University of Washington, Seattle 98195-7742
|
|
From: Benjamin L. <lin...@gm...> - 2009-08-31 20:15:13
|
Ethan Merritt wrote:
> On Monday 31 August 2009 11:26:16 Benjamin Lindner wrote:
>> Hello list,
>>
>> I came across a (for me) strange behaviour, which is, that if you use
>> the "labels" plotstyle increases the linestyle, although no line is drawn.
>
> That is entirely expected, but only if you realize that "linestyle" and
> "linetype" have evolved into misnomers. The linestyle or linetype is
> described by a structure that specifies far more than just the color.
> From term_api.h:
>
> typedef struct lp_style_type { /* contains all Line and Point properties */
> int pointflag; /* 0 if points not used, otherwise 1 */
> int l_type;
> int p_type;
> int p_interval; /* Every Nth point in style LINESPOINTS */
> double l_width;
> double p_size;
> TBOOLEAN use_palette;
> struct t_colorspec pm3d_color;
> /* ... more to come ? */
> } lp_style_type;
>
>
> The thing is, these properties affect points just as much as they affect
> lines per se. You still have to draw the point with some linewidth and
> some color, right? For that matter, what about plots "with linespoints"
> where the same set of properties applies to both the lines and the points.
>
> Which brings us to labels...
> One of the properties of a label is {{no}point}, which controls whether or
> not a point is drawn exactly at the coordinates given. If you select to
> have a point drawn for each label, the point properties have to come from
> somewhere and the obvious place is to take them from the "linestyle" of the
> current plot.
This is true, but if no point is drawn, then increasing the linetype is
an unneccesary side effect.
> So, for example, you might draw a plot containing many labeled data sets,
> and distinguish which point is from which dataset by the color/shape of the
> associated points. Make sense?
For this example you sketch, yes.
But let me sketch a different example: Let's say you plot your data
using a plotstyle involving some kind of graphical means, e.g.
histograms, or lines or linespoints. So the distinction between
different sets of data is already properly done by different colour
and/or different point types. Now you want to simply add numerical
labels to your e.g. histograms because you want to also print the actual
numerical value along with the bars. Then simply adding the labels
changes the line types and colours of your previous plot, even if no
additional line or point is drawn by adding the labels - just the text
is printed.
Then this is not what I would expect. It's an application of labels as
simply additional text to an exisiting graph.
benjamin
|
|
From: Ethan M. <merritt@u.washington.edu> - 2009-08-31 20:39:01
|
On Monday 31 August 2009 13:14:54 Benjamin Lindner wrote:
> Ethan Merritt wrote:
> > On Monday 31 August 2009 11:26:16 Benjamin Lindner wrote:
> > Which brings us to labels...
> > One of the properties of a label is {{no}point}, which controls whether or
> > not a point is drawn exactly at the coordinates given. If you select to
> > have a point drawn for each label, the point properties have to come from
> > somewhere and the obvious place is to take them from the "linestyle" of the
> > current plot.
>
> This is true, but if no point is drawn, then increasing the linetype is
> an unneccesary side effect.
>
> > So, for example, you might draw a plot containing many labeled data sets,
> > and distinguish which point is from which dataset by the color/shape of the
> > associated points. Make sense?
>
> For this example you sketch, yes.
> But let me sketch a different example: Let's say you plot your data
> using a plotstyle involving some kind of graphical means, e.g.
> histograms, or lines or linespoints. So the distinction between
> different sets of data is already properly done by different colour
> and/or different point types. Now you want to simply add numerical
> labels to your e.g. histograms because you want to also print the actual
> numerical value along with the bars. Then simply adding the labels
> changes the line types and colours of your previous plot, even if no
> additional line or point is drawn by adding the labels - just the text
> is printed.
> Then this is not what I would expect. It's an application of labels as
> simply additional text to an exisiting graph.
From my point of view, consistency requires that every clause of a plot command
consumes one increment of line type. Another example of this that is close to
what you describe:
set style data lines
plot "A.dat", "B.dat", "C.dat", "D.dat"
Suppose you run this script periodically, each time plotting the current
contents of files A, B, C, and D. Also suppose that for whatever reason
sometimes one or more of the files is empty. By requiring that each clause
of the plot command increments the color (linestyle), you end up with
consistent colors for all four data sets in every plot, even if not all of
them are present in every plot.
If you were to skip the increment just because in this particular plot no
lines of that color are being drawn, then it would mess up the overall
consistency of the line type assignments.
The same is true for your labeling case. You may "know" externally
that the labels you are adding should not be assigned a separate color
because they are paired with a particular plot that already has a color.
But how is gnuplot itself supposed to know this if you don't tell it?
In general if you add a clause to the plot command it describes a new set of
data and should get its own color assignment.
Of course, you are always free to specify an explicit color and/or
line style for each individual plot clause. Or in this case I suppose
you could just add the label clauses at the end of the command, where
they will not affect the order of the earlier ones.
Ethan
|