### gnuplot

#### Composite xrange in gnuplot

I have a periodic system and I want to fit some data for this system to a function, but I want to constrain to a range. Usually, if your range is from x_min to x_max this can be achieved with fit [x_min:x_max] f(x) "data" via a,b,c,.... However, because my system is periodic, I want to constrain to a range that contains a segment at the end of the array of x values and also at the beginning. That is, if x values are given within the interval [0:L], I want to include in the fit both [0:x_max] and [x_min:L], where in this case x_max < x_min. How can this be done?

How about this? fit [min1:max2] f(x) "data" u 1:($1 <= max1 || $1 >= min2 ? $2 : 1/0) via a,b,c,... That is, make use of the [:] for the outer range. I'm not sure it's much nicer but it is a little bit shorter. Alternatively, you could use set table in the following way: set table 'newdata' p [0:x_max] 'data' p [x_min:L] 'data' unset table fit f(x) 'newdata' via a,b,c,... Basically this writes a new file containing only the data between the two ranges. Arguably nicer, definitely not shorter!

I figured an ugly way to do it, but if anyone comes up with a nicer way I will accept that as the answer. Imagine the two ranges where you want to fit (or plot) the data are given by [min1:max1] and [min2:max2], then using a conditional fit and the "ignore" function 1/0 you can do the following: fit f(x) "data" u 1:( ($1 >= min1 && $1 <= max1) || ($1 >= min2 && $1 <= max2) ? $2 : 1/0) via a,b,c,... That is, if x is within the first interval or the second one, then use y as a value for the fit, otherwise ignore those data points. This approach should also work with plot, but I think something like a composite range operator [min1:max1 && min2:max2] (which does not work) would be more desirable.

### Related Links

how to plot data which has mostly true values in gnuplot?

GNUplot concatenate 2 macros in an xlabel

Determine min and max in gnuplot

Plot cyclic sum of some row data

How to count the number of indices in a Gnuplot input file

GNU Plot how to plot histogram in timeseries

Create groups of dots histogram with gnuplot

Gnuplot: Missing values on second y-axis

Gnuplot fat lines overlap with axis

Using relative paths in gnuplot plot files

increment of ytics in gnuplot

gnuplot: Plot and fit 2d function with two variables

Gnuplot: Plotting a path over a surface

How to mark 90 percentile in gnuplot

Is there a way to have gnuplot use xaxis time data, but skip certain intervals (e.g. non-trading hours)

How can I make gnuplot show coordinates of a plotted function which have same x value as the mouse pointer?