# How to obtain a framed plot with blank space where data that would normally extend to the blank space?

I have a large set of data where every line is in the form:

{x1, x2, x3, x4, x5}


The values in column x2 cab be much larger than 150.

I would like to plot the data in a framed list plot, using on the row where $x2\in[0,\, 150]$. I would also like the frame to be larger than the PlotRange specified interval, in order to label the different parts of the data (there are 7 of them) and for a label to appear next to a line using Epilog.

I have tried to use Epilog to label the lines without enlarging the frame and the labels are invisible. I have tried to use PlotRangePadding to enlarge the frame, but it enlarges the plot range too.

I have tried to select the data manually with the following code:

    list={};
For[i = 1, i < Length[data],
If[data[[i, 2]] > 0 && data[[i, 2]] < 150,
AppendTo[list, data[[i]]]];
i + 10]


but Mathematica crashes (the i + 10 is to reduce the data set).

Is there a way to obtain a plot with a plot range between 0 and 150, and the frame between 0 and 200, in order to have a white space where I can display the labels with Epilog?

• Select[x2, # <= 150] Aug 3, 2016 at 15:23
• AppendTo is very inefficient. If you are collecting data, use Reap and Sow. Also, For is way (I mean WAY) slower than Do, a mathematica-native version of For. Aug 3, 2016 at 15:34
• The problem with your code is that the value of i never changes (the last i + 10 does nothing), resulting in an infinite loop and crash. That being said, I believe Select is a better option to use here. That is, Select[data, AllTrue[#, 0<=#<=150&]&] Aug 3, 2016 at 15:35
• ok, I'll try that. I hadn't realized about the infinite loop Aug 3, 2016 at 15:40
• Pertaining to your question concerning making annotations with Epilog, it is unclear to me what you actually want to plot and how you want the final plot to look. Can you restate you problem with a clearer description of the plot? I have a feeling that the For-loop issue you have inserted is not relevant to your plotting issue. Aug 3, 2016 at 18:56

This answer only addresses your problem with For. Note that For should have the form

$\qquad$For[index-initializer, exit-test, index-incrementer, code-body]

which means your code will work when rewritten as

sample = {};
For[i = 1, i <= Length[data], i += 10,
If[data[[i, 2]] => 0 && data[[i, 2]] <= 150, AppendTo[sample, data[[i]]]]];
sample


but in Mathematica the following expression will produce the same result

Select[data[[;; ;; 10]], 0 <= #[[2]] <= 150. &]


and is not only more concise but executes much faster. Since the above may a bit cryptic for a beginner (and your question makes it almost certain you are beginner), here is a less concise but more easily understood equivalent.

Block[{test},
test[row_] := 0 <= row[[2]] <= 150.;
Select[Take[data, {1, -1, 10}], test]]