|
From: Ethan M. <merritt@u.washington.edu> - 2006-06-22 19:50:17
|
Do we have a utility routine somewhere that would convert
plot coordinates to graph or screen coordinates?
What I want to do is take a mouse-click location,
which is reported in plot coords, and keep track of
where that was on the screen.
The closest I can find is this routine in gnuplot_x11:
/* Convert X-window mouse coords to coordinate system of plot axes */
static void
mouse_to_coords(plot_struct *plot, XEvent *event,
double *x, double *y, double *x2, double *y2)
but it's the wrong direction, and not visible in the core code
anyhow.
--
Ethan A Merritt
Biomolecular Structure Center
University of Washington, Seattle WA
|
|
From: <br...@ph...> - 2006-06-23 22:40:50
|
Ethan Merritt wrote:
> Do we have a utility routine somewhere that would convert
> plot coordinates to graph or screen coordinates?
No. axis.h:AXIS_MAP() and AXIS_MAPBACK transform from data
('first'/'second') coordinates to terminal coordinates and back.
Going from terminal to 'screen' is trivial (just divide by term->xmax).
Transforming to 'graph' from data coordinates is quite easy: it's a
direct linear transformation using the axis_array[].min and .max
values.
The X11-specific one you would want to look at is mouse_to_axis.
But the real key to this is in mouse.c:MousePosToGraphPosReal().
It's based on macros from axis.h
|
|
From: j1n3l0 <nel...@gm...> - 2007-07-09 11:20:16
|
Hans-Bernhard Br=C3=B6ker wrote:
>=20
> Ethan Merritt wrote:
>> Do we have a utility routine somewhere that would convert=20
>> plot coordinates to graph or screen coordinates?
>=20
> No. axis.h:AXIS_MAP() and AXIS_MAPBACK transform from data=20
> ('first'/'second') coordinates to terminal coordinates and back.
> Going from terminal to 'screen' is trivial (just divide by term->xmax).
> Transforming to 'graph' from data coordinates is quite easy: it's a=20
> direct linear transformation using the axis_array[].min and .max
> values.
>=20
This thread is over a year old but I am in need of a solution. I am trying
to get the screen coordinates from my graph coordinates so I can generate a=
n
image map of my plots.
Is there a way to find out the values of {l|t|b|r}margins in pixels?
Currently the best I can do is use the "show margin" command, which just
tells me that the values are computed automatically, not what the values
are. If I knew the absolute values of these (in pixels) I could find the
coordinates of each point on my graph.
I think this would go some way to helping me solve my problem.
--=20
View this message in context: http://www.nabble.com/Is-there-a-way-of-conve=
rting-plot-coords-to-graph-coords--tf1832453.html#a11499886
Sent from the Gnuplot - Dev mailing list archive at Nabble.com.
|
|
From: Theo H. <th...@ph...> - 2007-07-14 00:35:03
|
j1n3l0 wrote:
>
> Hans-Bernhard Bröker wrote:
>> Ethan Merritt wrote:
>>> Do we have a utility routine somewhere that would convert
>>> plot coordinates to graph or screen coordinates?
>> No. axis.h:AXIS_MAP() and AXIS_MAPBACK transform from data
>> ('first'/'second') coordinates to terminal coordinates and back.
>> Going from terminal to 'screen' is trivial (just divide by term->xmax).
>> Transforming to 'graph' from data coordinates is quite easy: it's a
>> direct linear transformation using the axis_array[].min and .max
>> values.
>>
>
> This thread is over a year old but I am in need of a solution. I am trying
> to get the screen coordinates from my graph coordinates so I can generate an
> image map of my plots.
>
> Is there a way to find out the values of {l|t|b|r}margins in pixels?
> Currently the best I can do is use the "show margin" command, which just
> tells me that the values are computed automatically, not what the values
> are. If I knew the absolute values of these (in pixels) I could find the
> coordinates of each point on my graph.
>
> I think this would go some way to helping me solve my problem.
I'm not sure if it completely solves your problem, but new in 4.3 is a
feature that allows margins to be specified in terms of fractions of the
screen coordinate system. Since you presumably know the size of your
terminal's "screen", you can easily find where the borders of the graph
area are. This method will not work if you need (for whatever reason) to
have automatically calculated margins.
THeo
|
|
From: j1n3l0 <nel...@gm...> - 2007-07-19 10:54:22
|
I did solve my problem. I measured the distances for each margin and found
that there is a ratio system in place. My findings are summarised below:
=========================================================================
coords [x, y] = [ (lmargin + (abs(xmin - x)/xrange * xlength)), (tmargin +
(abs(ymax - y)/yrange * ylength)) ]
where:
lmargin is the length in pixels of the left margin
lmargin = 7 * gnuplot lmargin
xrange is the difference between the max and min x values
xrange = abs(xmax - xmin)
xlength is the length of the x axis in pixels
xlength = image_width - (lmargin + rmargin)
tmargin is the length in pixels of the top margin
tmargin = 11 * gnuplot tmargin
yrange is the difference between the max and min y values
yrange = abs(ymax - ymin)
ylength is the length of the y axis in pixels
ylength = image_height - (tmargin + bmargin)
=========================================================================
>From this I was able to construct a class which generates image maps of
Gnuplots on the fly.
Theo Hopman wrote:
>
> I'm not sure if it completely solves your problem, but new in 4.3 is a
> feature that allows margins to be specified in terms of fractions of the
> screen coordinate system. Since you presumably know the size of your
> terminal's "screen", you can easily find where the borders of the graph
> area are. This method will not work if you need (for whatever reason) to
> have automatically calculated margins.
>
This information will be useful in future. I can substitute my methods for
calculating the margins in pixels accordingly.
--
View this message in context: http://www.nabble.com/Is-there-a-way-of-converting-plot-coords-to-graph-coords--tf1832453.html#a11686342
Sent from the Gnuplot - Dev mailing list archive at Nabble.com.
|
|
From: Theo H. <th...@ph...> - 2007-07-19 13:58:57
|
j1n3l0 wrote: > I did solve my problem. I measured the distances for each margin and found > that there is a ratio system in place. My findings are summarised below: > > ========================================================================= > > coords [x, y] = [ (lmargin + (abs(xmin - x)/xrange * xlength)), (tmargin + > (abs(ymax - y)/yrange * ylength)) ] > > where: > > lmargin is the length in pixels of the left margin > > lmargin = 7 * gnuplot lmargin [...] > tmargin is the length in pixels of the top margin > > tmargin = 11 * gnuplot tmargin I'm glad your were able to solve your problem, but do note that your method will break if you use a different size default font. Margins are specified in terms of characters, and the font you're using happens to report a width of 7 and a height of 11. It'll likely break if you use a different terminal (probably because of a different default font), or if you add a title. Of course, good enough is often good enough :) THeo |