3
$\begingroup$

I have two lists which I transposed. Now, I need to ListPlot only pairs where both numbers are greater than 0 and skip those with at least 0 in pair. E.g.: to plot {1,5}, not to plot {0,20} etc. Can you help me to figure it out?

x = {1, 5, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0};
y = {5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60};
p = Transpose[{x, y}];

Thanks for help!

$\endgroup$

1 Answer 1

4
$\begingroup$

You can use Select with FreeQ[0] as the selector function:

selected = Select[FreeQ[0]] @ p

{{1, 5}, {5, 10}, {3, 15}}

ListPlot[selected]

enter image description here

You can also use Cases or DeleteCases or Pick or ReplaceAll as follows:

Cases[{Except[0]..}] @ p
DeleteCases[{0,_}|{_,0}] @ p
Pick[p, Unitize[Times @@@ p], 1]
p /. {0,_}|{_,0} -> Nothing
$\endgroup$
1
  • $\begingroup$ Thank you, It helped a lot. :-) $\endgroup$
    – Vocis
    Commented Aug 8, 2019 at 13:52

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.