[prev in list] [next in list] [prev in thread] [next in thread]
List: gnuplot-info
Subject: Re: [Gnuplot-info] How to dynamically specify color for drawing
From: lilu29 <lulixiao () gmail ! com>
Date: 2009-01-10 3:43:14
Message-ID: 21384557.post () talk ! nabble ! com
[Download RAW message or body]
Hi, guys
Nobody answers this question, so I spent nearly 4 hours to hack Gnuplot in
order to find out how to use this function for specifying color from data
file. I didn't read its source code before, so starting from the scratch.
The requirement:
Gnuplot4.3 source code,
grep
That's enough.
This post only represents my own opinion, so there may be some faults,
welcome to point them out.
Because, when I hacked the source code, I added a few print statements,
maybe there exists some wrong line numbers.
But I wrote out the full function names and variable names, wrong line
numbers don't effect reading.
1) Where is the main function for starting
The entry main function is in "plot.c": int gnu_main(), or int main()
2) Which function plots circles or other objects
void place_objects() : graphics.c
In this function, you can find "case OBJ_CIRCLE". You can also see
"do_arc(x1, y1, radius, e->arc_begin, e->arc_end,0)"
do_arc() really draws circles.:term.c
One of its parameters "style" controls the drawing style.
3) The drawing style mentioned in (2) is set in place_objects and actually
from object* listhead which is the first parameters in this function. We can
also find out that this parameter is a list of objects, so gnuplot plots
objects in this list one by one.
4) Which function invokes place_objects() and give parameter "object*
listhead"
void do_plot(): graphics.c
On line 1567 of graphics.c, it invokes place_object(first_object,****),
first_object is a global variable which a head of object list.
void refresh_request(): command.c --this function invokes
"do_plot(first_plot)"
first_plot is also a global variable set in eval_plots(): plot2d.c
On line 1414 in this file, we see top_ptr=&(first_plot)
In this file, we also see a imporant variable "struct curve_poins*
this_plot", this variable specifies the drawing style. We can find many
drawing properties set in this function. But the most important statement is
line 1993:(get_data(this_plot))
5)get_data(this_plot): plot2d.c
In this function, we can find "TBOOLEAN variable_color", it decides whether
we can specify color dynamically.
Another important variable for setting color value (RGB value) is "double
variable_color_value ". This value is real color value for drawing objects.
This function also points out:
the min_cols and max_cols of data file for drawing circle are 3 and 4.
(line 472)
The comment says /*3+ possible variable color*/
So we really confirm that color for each circle can be set at the 4th column
of data file.
we can see that the value of variable_color_value is from data file:
"variable_color_value = v[--j]"
v[] is a array read from data file. This array is also processed through
some function specified at "using func($1):func($2)***"
6) Now the important is: how to let variable_color ==true
on line 340 in plot2d.c, we can find out two conditions can make this value
true.
We track the first condition,
"current_plot->lp_properties.pm3d_color.type==TC_RGB"
color.type is set at "parse_colorspec()", while "parse_colorspec()" is
invoked in lp_parse(). Both functions are in misc.c.
> From " lp_parse()", we know that we need to specify "lt" in the command line
to invoke parse_colorspec()
> From "parse_colorspec" we need to specify "rgb " in command.
In conclusion, to set circle color from data file, we should:
a, the format of data file
x y radius color_clue
ps: color_clue can be the real RGB value or any varialbe which we can
calculate RGB from it
b, the rgb command
plot "data_file" using 1:2:3:yourColorFunc($4, or the total four columns)
with circles lt rgb var
or
plot "data_file" using 1:2:3:yourColorFunc($4, or the total four columns)
with circles lt rgbcolor var
or
plot "data_file" using 1:2:3:yourColorFunc($4, or the total four columns)
with circles lt rgbcolor variable
or
plot "data_file" using 1:2:3:yourColorFunc($4, or the total four columns)
with circles lt rgb variable
(rgb==rgbcolor; var==variable)
This command is enough, we do not need to do any other command.
lilu29 wrote:
>
> Hi, everyone
> Gnuplot4.3 has a new type for drawing circle, and in its manual, it says
> "An optinal 4th column may be used to specify color information". But it
> doesn't give any example of using this function. All its examples for
> drawing circle are specifying color statically.
>
> What I want to do is: I want to draw circles using following input data,
> each circle is defined by one line, the 4th column is the painting color.
> What should I do???? I tried
> plot "file" using 1:2:3:4 with circles lc rgb $4
> plot "file" using 1:2:3:4 with circles lc rgb variable
> they all don't work.
> Can someone give me some hints?
>
> Thank you very much!
>
> My input data's format is:
> x y radius color
> 2 3 4 "yellow"
> 1 1 5 "red"
> .............
>
>
>
>
--
View this message in context: \
http://www.nabble.com/How-to-dynamically-specify-color-for-drawing-circle-in-Gnuplot4.3-tp21376845p21384557.html
Sent from the Gnuplot - User mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It is the best place to buy or sell services for
just about anything Open Source.
http://p.sf.net/sfu/Xq1LFB
_______________________________________________
Gnuplot-info mailing list
Gnuplot-info@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gnuplot-info
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic