Hi Fred,
from the java side, plot.useTemplate should work also after a plot has
been displayed, but you have to use plot.updateImage() thereafter.
I have not tried, however; let me know if it does not work.
The macro call Plot.useTemplate currently does not work after showing
the plot, but this can be be changed if desired.
Michael
________________________________________________________________
On 26.01.24 02:16, Fred Damen wrote:
Greetings Michael,
So I tried it. It turns out that the order matters...
plot.setLimitsToFit(true);
plot.useTemplate(prevPlot, Plot.COPY_SIZE+Plot.X_RANGE+Plot.COPY_AXIS_STYLE);
plot.show();
When I first used setLimitsToFit, ages ago, it would only work after show.
It seems that now it also works before show. useTemplate does not seem to
work after show.
Thanks,
Fred
On Thu, January 25, 2024 1:34 pm, Michael Schmid wrote:
Hi Fred,
hmm, I don't fully understand your application.
Anyhow, you can use setLimitsToFit and *thereafter* transfer the limits
of one axis (here the x axis) and also its 'log' property with
plot.useTemplate (having the Plot.X_RANGE+Plot.COPY_AXIS_STYLE flags).
As long as you don't specify the Plot.Y_RANGE or Plot.ALL_AXES_RANGE
flags, the limits in y won't be affected by useTemplate, and will remain
as set by setLimitsToFit.
In other words, plot.setLimitsToFit just sets the values of the limits
once when you call it. It does not make the plot behave a different way
in the future. Plot.setLimitsToFit is the equivalent to clicking the
gray "F" in the bottom-left corner of the plot with the mouse; you can
change the limits thereafter as you like.
Simply try it.
------------------------------
A side note:
It is safer to combine flags with bitwise OR, e.g.
Plot.X_RANGE | Plot.COPY_AXIS_STYLE
In most cases it makes no difference, but sometimes it does, if one flag
gets specified twice.
E.g. I can have
defaultFlags = COPY_SIZE | COPY_CONTENTS_STYLE;
and somewhere later in the code
moreFlags = defaultFlags | COPY_LEGEND | COPY_EXTRA_OBJECTS;
This works with either bitwise OR (|) or adding (+).
A year later I change the first line to
defaultFlags = COPY_SIZE | COPY_CONTENTS_STYLE | COPY_LEGEND;
because I find out that I always want to copy the legend. Further down,
I still have (but I don't remember any more after a year)
moreFlags = defaultFlags | COPY_LEGEND | COPY_EXTRA_OBJECTS;
With the bitwise OR, it is ok:
COPY_LEGEND | COPY_LEGEND = 0x40 | 0x40 = 0x40
However, after changing the defaultFlags to include COPY_LEGEND, it
won't work if I had used '+' signs:
moreFlags = defaultFlags + COPY_LEGEND + COPY_EXTRA_OBJECTS;
Now we will have COPY_LEGEND twice in the sum.
COPY_LEGEND + COPY_LEGEND = 0x40 + 0x40 = 0x80
This clears the COPY_LEGEND flag, and flag 0x80 = COPY_AXIS_STYLE will
be set.
Similarily, we have
X_RANGE = 0x1;
Y_RANGE = 0x2;
ALL_AXES_RANGE = X_RANGE | Y_RANGE; //= 0x3
You may combine them with
X_RANGE | ALL_AXES_RANGE, but *not*
X_RANGE + ALL_AXES_RANGE
because the latter would be 1 + 3 = 4, and neither X_RANGE nor Y_RANGE
will be included in the result.
(For readability, I have omitted the preceding "Plot." for the flag names)
Best,
Michael
________________________________________________________________
On 25.01.24 19:49, Fred Damen wrote:
Greetings Michael,
So... Is there a way to get the plot.useTemplate to override the
plot.setLimitsToFit, e.g., place plot.useTemplate after
plot.setLimitsToFit in the code???
The reason I ask is that the actual plotting code is generic standalone
plugin and sometimes, as determined when viewing the plots, the user
would
like to view the results of a different ROI in the same format... In the
case here, the only thing that changes is the y values. In the actual
code
there are 6 y curves plotted, and thus the use of plot.setLimitsToFit.
If
I were to implement this fancy limiting in my code using plot.setLimits
would plot.useTemplate still not dominate?
Thanks,
Fred
On Thu, January 25, 2024 4:06 am, Michael Schmid wrote:
Hi Fred,
your data contain the value x=0. Thus, plot.setLimitsToFit forces the
plot to include the value x=0, which forces the x axis to be linear,
not
logarithmic.
If you have only positive data, or if you don't call setLimitsToFit,
useTemplate with Plot.COPY_AXIS_STYLE keeps the axis logarithmic.
Michael
________________________________________________________________
On 25.01.24 00:42, Fred Damen wrote:
Greeting,
I am trying to maintain the logarithmic axis through successive plots,
see
below. To reproduce, you...
Run the below plugin.
Click "Press me"
Choose More>> Set Range...
Set X From to 0.1
Set Log X Axis
Click OK
Click "Press me"
The X axis is no longer logarithmic.
Choosing More>> Set Range...
reveals that X From is now "0" again, albeit Log X Axis is still
set...
Q: Is just X_RANGE required for my requirement, or is COPY_AXIS_STYLE
also
required?
Fred
import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import java.awt.event.*;
import ij.plugin.*;
import ij.plugin.frame.*;
public class TestuseTemplate implements PlugIn {
PlotWindow pwin = null;
Plot prevPlot = null;
public void run(String arg) {
GenericDialog gd = new NonBlockingGenericDialog("test
useTemplate");
gd.addButton("Press me",new ActionListener() {
public void actionPerformed(ActionEvent e) {
Plot plot = new Plot("Title", "X", "Y");
plot.addPoints(new float[]{0,10,100,1000},new
float[]{0,10,100,1000},Plot.LINE);
if (prevPlot != null)
plot.useTemplate(prevPlot,
Plot.COPY_SIZE+Plot.X_RANGE+Plot.COPY_AXIS_STYLE);
if (pwin==null)
pwin = plot.show();
else
pwin.drawPlot(plot);
plot.setLimitsToFit(true);
prevPlot = plot;
}
});
gd.showDialog();
}
}
--
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
--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html