4
$\begingroup$

How to extract the second lowest and the second largest values of each row, and plot them as upper and lower graphs? I try with TakeLargest (or TakeSmallest) as discussed here, but I do not want them sorted in ascending/descending order.

I want the graph to be like this. Yes, we can do that with Min, Max, Mean. But how to manipulate/extract any data that I could have without changing the originality of its order?

Here is some example of the data.

data={{0.3,0.538102,0.760004,0.895921,0.959015,0.984521,0.99425,0.997877,0.999218,0.185006,0.381593},

{0.3,0.538102,0.760004,0.895921,0.959015,0.984521,0.99425,0.180053,0.37379,0.618694,0.815178},                

{0.3,0.538102,0.760004,0.895921,0.959015,0.984521,0.99425,0.997877,0.999218,0.999712,0.999894},                

{0.3,0.538102,0.760004,0.895921,0.959015,0.984521,0.99425,0.997877,0.522662,0.748515,0.889997},                

{0.3,0.538102,0.760004,0.895921,0.959015,0.984521,0.99425,0.997877,0.999218,0.568709,0.781868},                

{0.3,0.538102,0.760004,0.895921,0.959015,0.984521,0.99425,0.997877,0.999218,0.999712,0.105905},                

{0.3,0.538102,0.760004,0.895921,0.959015,0.984521,0.99425,0.491513,0.724331,0.877186,0.951017},                

{0.3,0.538102,0.760004,0.895921,0.959015,0.984521,0.99425,0.451753,0.691344,0.858927,0.943021},                

{0.3,0.538102,0.760004,0.895921,0.959015,0.984521,0.99425,0.997877,0.999218,0.999712,0.0995195},                

{0.3,0.538102,0.760004,0.895921,0.959015,0.984521,0.43541,0.677037,0.850711,0.939357,0.976801}};

I do try with MaximalBy, but I don't think my extraction technique is correct. I'm not expecting any overlap between upper and lower graphs.

Show[
 ListLinePlot[Mean[MaximalBy[data, Last, 6]], PlotRange -> Full, 
  DataRange -> {0, 30}, PlotStyle -> Red],
 ListLinePlot[Mean[MinimalBy[data, First, 4]], PlotRange -> Full, 
  DataRange -> {0, 30}, PlotStyle -> Blue]
 ]

This sample does not vary much, but it was part of a larger dataset.

Thanks in advance for the guidance and help.

$\endgroup$

2 Answers 2

10
$\begingroup$
ListLinePlot[{
  RankedMax[#, 2] & /@ data,
  RankedMin[#, 2] & /@ data
  }]
$\endgroup$
1
  • $\begingroup$ I was not aware of Ranked* functions. Thanks. Your solution is quite elegant. I guess it would also work with jagged arrays as well whereas a Transpose based solution would not. $\endgroup$
    – Syed
    Apr 29, 2022 at 15:45
3
$\begingroup$

With data as presented in the OP, the second lowest and the second highest entries (slsh) in the Sorted data are:

slsh = Transpose[#[[{2, -2}]] & /@ (Sort /@ data)]

ListLinePlot[slsh
 , PlotStyle -> {{Thick, Blue}
   , {Thick, Red}
   }
 , Mesh -> All
 , Filling -> 1 -> {2}
 ]

enter image description here


alldata = Transpose[(Sort /@ data)]

enter image description here

$\endgroup$
4
  • $\begingroup$ The filling region helps to highlight the area of interest. Is it possible to calculate the percentage of the shaded area? **Note: Thank you for showing the method with Transpose & Sort to plot the region, I couldn't think of that. $\endgroup$
    – nightcape
    Apr 29, 2022 at 16:27
  • $\begingroup$ % of the area compared to what? The entire area? I think you can start a fresh post with this query. First, the shaded area will have to be converted to a polygon. Then the same will be done with the entire area before a percentage can be calculated. I say this because it is a general policy on stack sites to limit the Q/A to one focused discussion per page. $\endgroup$
    – Syed
    Apr 29, 2022 at 17:14
  • $\begingroup$ Yes, I'll work on the problem, perhaps one with a more interesting dataset, and post another question. On another note, your answer here does help, but I may have to accept Henrik's for now $\endgroup$
    – nightcape
    Apr 30, 2022 at 15:29
  • $\begingroup$ @nightcape That is the better answer for sure. $\endgroup$
    – Syed
    Apr 30, 2022 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.