Plot.addNormalizedText

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Plot.addNormalizedText

CARL Philippe (LBP)
Dear all,
I hope you are still doing well despite the "war" that is going on right now.
I would have a quite silly question, namely within the Plot macro methods there is a
Plot.drawLine method using the coordinate system defined by Plot.setLimits()
and a
Plot.drawNormalizedLine method using an absolute coordinate system, with (0,0) at the top left and (1,1) at the lower right corner.
But for adding a text within a plot windows, there is only the Plot.addText method which is actually using the absolute coordinate system.
Thus would it be possible to have as well a method using the coordinate system defined by Plot.setLimits() ?
An issue I already see for my request of is that if we want to be within the same typos than for the drawLine (and add a Plot.addNormalizedText method), there would be a kind of breakage within the old macros which would be using the Plot.addText method. Unless of course another method name would be chosen.
Thanking you very much in advance for your lighting, I wish you a nice day.
My best regards,
Philippe

Philippe CARL
Laboratoire de Bioimagerie et Pathologies
UMR 7021 CNRS - Université de Strasbourg
Faculté de Pharmacie
74 route du Rhin
67401 ILLKIRCH
Tel : +33(0)3 68 85 42 89

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Plot.addNormalizedText

Schmid, Michael
Hi Philippe,

yes, the macro call Plot.addText("text", x, y) (synonymous with
Plot.drawLabel) uses normalized coordinates (range 0-1 for x and y). To
ensure compatibility, it is clear that it must not be renamed to
"addNormalizedText".

There is another option, however: One can have macro code that gets
executed at each point(x, y) of a data set:
   plot.add(macroCode, xPoints, yPoints);
where macroCode can be e.g.
   "code: setFont('sanserif',12*s,'bold
anti');drawString("text",x-14*s,y-4*s);"
For these macros, the values x&y are the screen coordinates of the
point, s is a scale factor (required for high-resolution plots), and i
is the index of the point. The data values are accassible with xval and
yval, so you can also encode these in the text.

See help>Examples>Plots>Custom Plot Symbols for examples.



[By the way, in the Java API, for historic reasons the method with
normalized coordinates is named addLabel(x, y, text); that with data
coordinates addText(text, x, y).]

Michael
_____________________________________________________________________


On 09/04/2020 12:10 pm, CARL Philippe (LBP) wrote:

> Dear all,
> I hope you are still doing well despite the "war" that is going on right now.
> I would have a quite silly question, namely within the Plot macro methods there is a
> Plot.drawLine method using the coordinate system defined by Plot.setLimits()
> and a
> Plot.drawNormalizedLine method using an absolute coordinate system, with (0,0) at the top left and (1,1) at the lower right corner.
> But for adding a text within a plot windows, there is only the Plot.addText method which is actually using the absolute coordinate system.
> Thus would it be possible to have as well a method using the coordinate system defined by Plot.setLimits() ?
> An issue I already see for my request of is that if we want to be within the same typos than for the drawLine (and add a Plot.addNormalizedText method), there would be a kind of breakage within the old macros which would be using the Plot.addText method. Unless of course another method name would be chosen.
> Thanking you very much in advance for your lighting, I wish you a nice day.
> My best regards,
> Philippe
>
> Philippe CARL
> Laboratoire de Bioimagerie et Pathologies
> UMR 7021 CNRS - Université de Strasbourg
> Faculté de Pharmacie
> 74 route du Rhin
> 67401 ILLKIRCH
> Tel : +33(0)3 68 85 42 89
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Plot.addNormalizedText

CARL Philippe (LBP)
Dear Michael,
Thanks a lot for your (as always) very sharp and smart answer!
I didn't know about this macroCode feature within the Plot macro methods and this will be adding another string to my bow.
Nevertheless, I would have two questions connected to it.
First let's say I have an array of Strings, thus is it possible to pass it with this feature and how?
I tried this without any success:
        colors    = newArray("black", "blue", "cyan", "lightGray", "gray", "darkGray", "green", "magenta", "orange", "pink", "red", "yellow");
        indexCode = "code: setFont('sanserif',14*s,'bold anti');drawString(colors[i], x - 3 * s, y * s);"
Also within a macro I use now this feature and after adding the text through the macroCode entry I add a legend using the method:
        Plot.addLegend("", "top-right");
all labels being previously defined through a Plot.add(type, xValues, yValues, label) method.
Very unfortunately I get a last entry being "setFont('sanserif',14*s,'bold anti');drawString(c..." within the legend.
Thus would there a way to get the legend labels entries that I could then set again after having added the macroCode entry?
Thanks a lot in advance.
My best regards,
Philippe

----- Mail original -----
De: "Michael Schmid" <[hidden email]>
À: "imagej" <[hidden email]>
Envoyé: Jeudi 9 Avril 2020 12:51:04
Objet: Re: Plot.addNormalizedText

Hi Philippe,

yes, the macro call Plot.addText("text", x, y) (synonymous with
Plot.drawLabel) uses normalized coordinates (range 0-1 for x and y). To
ensure compatibility, it is clear that it must not be renamed to
"addNormalizedText".

There is another option, however: One can have macro code that gets
executed at each point(x, y) of a data set:
   plot.add(macroCode, xPoints, yPoints);
where macroCode can be e.g.
   "code: setFont('sanserif',12*s,'bold
anti');drawString("text",x-14*s,y-4*s);"
For these macros, the values x&y are the screen coordinates of the
point, s is a scale factor (required for high-resolution plots), and i
is the index of the point. The data values are accassible with xval and
yval, so you can also encode these in the text.

See help>Examples>Plots>Custom Plot Symbols for examples.



[By the way, in the Java API, for historic reasons the method with
normalized coordinates is named addLabel(x, y, text); that with data
coordinates addText(text, x, y).]

Michael
_____________________________________________________________________


On 09/04/2020 12:10 pm, CARL Philippe (LBP) wrote:

> Dear all,
> I hope you are still doing well despite the "war" that is going on right now.
> I would have a quite silly question, namely within the Plot macro methods there is a
> Plot.drawLine method using the coordinate system defined by Plot.setLimits()
> and a
> Plot.drawNormalizedLine method using an absolute coordinate system, with (0,0) at the top left and (1,1) at the lower right corner.
> But for adding a text within a plot windows, there is only the Plot.addText method which is actually using the absolute coordinate system.
> Thus would it be possible to have as well a method using the coordinate system defined by Plot.setLimits() ?
> An issue I already see for my request of is that if we want to be within the same typos than for the drawLine (and add a Plot.addNormalizedText method), there would be a kind of breakage within the old macros which would be using the Plot.addText method. Unless of course another method name would be chosen.
> Thanking you very much in advance for your lighting, I wish you a nice day.
> My best regards,
> Philippe
>
> Philippe CARL
> Laboratoire de Bioimagerie et Pathologies
> UMR 7021 CNRS - Université de Strasbourg
> Faculté de Pharmacie
> 74 route du Rhin
> 67401 ILLKIRCH
> Tel : +33(0)3 68 85 42 89
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Plot.addNormalizedText

Schmid, Michael
Dear Philippe,

this partly works for me:

     xValues = newArray(11, 20, 33, 46, 61, 82);
     yValues = newArray(41, 50, 58, 62, 65, 68);

//the following should be one line:
     letterCode = "code: c = newArray('black', 'blue', 'cyan',
'lightGray', 'gray', 'darkGray', 'green', 'magenta', 'orange', 'pink',
'red', 'yellow');setFont('sanserif',14*s,'bold
anti');drawString(c[i],x-4*s,y+8*s);"

     Plot.create("Plot with Custom Symbols_", "X", "Y");
     Plot.setLimits(0, 90, -5, 80 );
     Plot.setFrameSize(700, 400);
     Plot.setColor("#001010");
     Plot.add(letterCode, xValues, yValues);

     Plot.addLegend("colors", "auto");
     Plot.show;


You have to put the array into the macro; it won't know about the
"external" macro creating the plot.
Also note that a macro String enclosed in quotes needs either escaped
quotes or single quotes for String constants in the macro String.

There seems to be a bug with colors; I needed the
Plot.setColor("#001010");
to get it working.

For the legend, it takes the first symbol (which is a bold "black", but
it only reserves the space usually needed for a symbol. The only
workaround that I can think of is having a first data point with NaN
coordinates that is used for the legend (here an 'x'):

     xValues = newArray(NaN, 11, 20, 33, 46, 61, 82);
     yValues = newArray(NaN, 41, 50, 58, 62, 65, 68);
    letterCode = "code: c = newArray('x','black', 'blue', 'cyan',
'lightGray', 'gray', 'darkGray', 'green', 'magenta', 'orange', 'pink',
'red', 'yellow');setFont('sanserif',14*s,'bold
anti');drawString(c[i],x-4*s,y+8*s);"


Best,

Michael
________________________________________________________________
On 09.04.20 17:09, CARL Philippe (LBP) wrote:

> Dear Michael,
> Thanks a lot for your (as always) very sharp and smart answer!
> I didn't know about this macroCode feature within the Plot macro methods and this will be adding another string to my bow.
> Nevertheless, I would have two questions connected to it.
> First let's say I have an array of Strings, thus is it possible to pass it with this feature and how?
> I tried this without any success:
> colors    = newArray("black", "blue", "cyan", "lightGray", "gray", "darkGray", "green", "magenta", "orange", "pink", "red", "yellow");
> indexCode = "code: setFont('sanserif',14*s,'bold anti');drawString(colors[i], x - 3 * s, y * s);"
> Also within a macro I use now this feature and after adding the text through the macroCode entry I add a legend using the method:
> Plot.addLegend("", "top-right");
> all labels being previously defined through a Plot.add(type, xValues, yValues, label) method.
> Very unfortunately I get a last entry being "setFont('sanserif',14*s,'bold anti');drawString(c..." within the legend.
> Thus would there a way to get the legend labels entries that I could then set again after having added the macroCode entry?
> Thanks a lot in advance.
> My best regards,
> Philippe
>
> ----- Mail original -----
> De: "Michael Schmid" <[hidden email]>
> À: "imagej" <[hidden email]>
> Envoyé: Jeudi 9 Avril 2020 12:51:04
> Objet: Re: Plot.addNormalizedText
>
> Hi Philippe,
>
> yes, the macro call Plot.addText("text", x, y) (synonymous with
> Plot.drawLabel) uses normalized coordinates (range 0-1 for x and y). To
> ensure compatibility, it is clear that it must not be renamed to
> "addNormalizedText".
>
> There is another option, however: One can have macro code that gets
> executed at each point(x, y) of a data set:
>     plot.add(macroCode, xPoints, yPoints);
> where macroCode can be e.g.
>     "code: setFont('sanserif',12*s,'bold
> anti');drawString("text",x-14*s,y-4*s);"
> For these macros, the values x&y are the screen coordinates of the
> point, s is a scale factor (required for high-resolution plots), and i
> is the index of the point. The data values are accassible with xval and
> yval, so you can also encode these in the text.
>
> See help>Examples>Plots>Custom Plot Symbols for examples.
>
>
>
> [By the way, in the Java API, for historic reasons the method with
> normalized coordinates is named addLabel(x, y, text); that with data
> coordinates addText(text, x, y).]
>
> Michael
> _____________________________________________________________________
>
>
> On 09/04/2020 12:10 pm, CARL Philippe (LBP) wrote:
>> Dear all,
>> I hope you are still doing well despite the "war" that is going on right now.
>> I would have a quite silly question, namely within the Plot macro methods there is a
>> Plot.drawLine method using the coordinate system defined by Plot.setLimits()
>> and a
>> Plot.drawNormalizedLine method using an absolute coordinate system, with (0,0) at the top left and (1,1) at the lower right corner.
>> But for adding a text within a plot windows, there is only the Plot.addText method which is actually using the absolute coordinate system.
>> Thus would it be possible to have as well a method using the coordinate system defined by Plot.setLimits() ?
>> An issue I already see for my request of is that if we want to be within the same typos than for the drawLine (and add a Plot.addNormalizedText method), there would be a kind of breakage within the old macros which would be using the Plot.addText method. Unless of course another method name would be chosen.
>> Thanking you very much in advance for your lighting, I wish you a nice day.
>> My best regards,
>> Philippe
>>
>> Philippe CARL
>> Laboratoire de Bioimagerie et Pathologies
>> UMR 7021 CNRS - Université de Strasbourg
>> Faculté de Pharmacie
>> 74 route du Rhin
>> 67401 ILLKIRCH
>> Tel : +33(0)3 68 85 42 89
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Plot.addNormalizedText

CARL Philippe (LBP)
Dear Michael,
Thanks a lot for everything!
Happy week-end and eastern for you!
My best regards,
Philippe

----- Mail original -----
De: "Michael Schmid" <[hidden email]>
À: "imagej" <[hidden email]>
Envoyé: Jeudi 9 Avril 2020 17:49:54
Objet: Re: Plot.addNormalizedText

Dear Philippe,

this partly works for me:

     xValues = newArray(11, 20, 33, 46, 61, 82);
     yValues = newArray(41, 50, 58, 62, 65, 68);

//the following should be one line:
     letterCode = "code: c = newArray('black', 'blue', 'cyan',
'lightGray', 'gray', 'darkGray', 'green', 'magenta', 'orange', 'pink',
'red', 'yellow');setFont('sanserif',14*s,'bold
anti');drawString(c[i],x-4*s,y+8*s);"

     Plot.create("Plot with Custom Symbols_", "X", "Y");
     Plot.setLimits(0, 90, -5, 80 );
     Plot.setFrameSize(700, 400);
     Plot.setColor("#001010");
     Plot.add(letterCode, xValues, yValues);

     Plot.addLegend("colors", "auto");
     Plot.show;


You have to put the array into the macro; it won't know about the
"external" macro creating the plot.
Also note that a macro String enclosed in quotes needs either escaped
quotes or single quotes for String constants in the macro String.

There seems to be a bug with colors; I needed the
Plot.setColor("#001010");
to get it working.

For the legend, it takes the first symbol (which is a bold "black", but
it only reserves the space usually needed for a symbol. The only
workaround that I can think of is having a first data point with NaN
coordinates that is used for the legend (here an 'x'):

     xValues = newArray(NaN, 11, 20, 33, 46, 61, 82);
     yValues = newArray(NaN, 41, 50, 58, 62, 65, 68);
    letterCode = "code: c = newArray('x','black', 'blue', 'cyan',
'lightGray', 'gray', 'darkGray', 'green', 'magenta', 'orange', 'pink',
'red', 'yellow');setFont('sanserif',14*s,'bold
anti');drawString(c[i],x-4*s,y+8*s);"


Best,

Michael
________________________________________________________________
On 09.04.20 17:09, CARL Philippe (LBP) wrote:

> Dear Michael,
> Thanks a lot for your (as always) very sharp and smart answer!
> I didn't know about this macroCode feature within the Plot macro methods and this will be adding another string to my bow.
> Nevertheless, I would have two questions connected to it.
> First let's say I have an array of Strings, thus is it possible to pass it with this feature and how?
> I tried this without any success:
> colors    = newArray("black", "blue", "cyan", "lightGray", "gray", "darkGray", "green", "magenta", "orange", "pink", "red", "yellow");
> indexCode = "code: setFont('sanserif',14*s,'bold anti');drawString(colors[i], x - 3 * s, y * s);"
> Also within a macro I use now this feature and after adding the text through the macroCode entry I add a legend using the method:
> Plot.addLegend("", "top-right");
> all labels being previously defined through a Plot.add(type, xValues, yValues, label) method.
> Very unfortunately I get a last entry being "setFont('sanserif',14*s,'bold anti');drawString(c..." within the legend.
> Thus would there a way to get the legend labels entries that I could then set again after having added the macroCode entry?
> Thanks a lot in advance.
> My best regards,
> Philippe
>
> ----- Mail original -----
> De: "Michael Schmid" <[hidden email]>
> À: "imagej" <[hidden email]>
> Envoyé: Jeudi 9 Avril 2020 12:51:04
> Objet: Re: Plot.addNormalizedText
>
> Hi Philippe,
>
> yes, the macro call Plot.addText("text", x, y) (synonymous with
> Plot.drawLabel) uses normalized coordinates (range 0-1 for x and y). To
> ensure compatibility, it is clear that it must not be renamed to
> "addNormalizedText".
>
> There is another option, however: One can have macro code that gets
> executed at each point(x, y) of a data set:
>     plot.add(macroCode, xPoints, yPoints);
> where macroCode can be e.g.
>     "code: setFont('sanserif',12*s,'bold
> anti');drawString("text",x-14*s,y-4*s);"
> For these macros, the values x&y are the screen coordinates of the
> point, s is a scale factor (required for high-resolution plots), and i
> is the index of the point. The data values are accassible with xval and
> yval, so you can also encode these in the text.
>
> See help>Examples>Plots>Custom Plot Symbols for examples.
>
>
>
> [By the way, in the Java API, for historic reasons the method with
> normalized coordinates is named addLabel(x, y, text); that with data
> coordinates addText(text, x, y).]
>
> Michael
> _____________________________________________________________________
>
>
> On 09/04/2020 12:10 pm, CARL Philippe (LBP) wrote:
>> Dear all,
>> I hope you are still doing well despite the "war" that is going on right now.
>> I would have a quite silly question, namely within the Plot macro methods there is a
>> Plot.drawLine method using the coordinate system defined by Plot.setLimits()
>> and a
>> Plot.drawNormalizedLine method using an absolute coordinate system, with (0,0) at the top left and (1,1) at the lower right corner.
>> But for adding a text within a plot windows, there is only the Plot.addText method which is actually using the absolute coordinate system.
>> Thus would it be possible to have as well a method using the coordinate system defined by Plot.setLimits() ?
>> An issue I already see for my request of is that if we want to be within the same typos than for the drawLine (and add a Plot.addNormalizedText method), there would be a kind of breakage within the old macros which would be using the Plot.addText method. Unless of course another method name would be chosen.
>> Thanking you very much in advance for your lighting, I wish you a nice day.
>> My best regards,
>> Philippe
>>
>> Philippe CARL
>> Laboratoire de Bioimagerie et Pathologies
>> UMR 7021 CNRS - Université de Strasbourg
>> Faculté de Pharmacie
>> 74 route du Rhin
>> 67401 ILLKIRCH
>> Tel : +33(0)3 68 85 42 89
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html