Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I tried to combine three and more graphics with the Show command; but sometimes there is no data, so some of the graphics are empty lists. I tried this:

Show[ grPacing, grAcq, If[grNewMap !={}, grNewMap] ... ]

But there are a lot of errors.

Any ideas?

Thank you, Liad.

share|improve this question

3 Answers 3

Show has no problem with empty lists:

p1 = Plot[Sin[x], {x, -2, 2}];
p2 = Graphics[{Red, Circle[]}];

Show[p1, p2, {}]

enter image description here

share|improve this answer

The problem you are seing is that If[False,x] returns Null, so you end up with Show[plot1,plot2,Null]

Here's a way around that:

grPacing = Plot[x, {x, 0, 1}];
grAcq = Plot[x^2, {x, 0, 1}];
grNewMap = {};
Show[grPacing, grAcq,If[grNewMap =!= {}, grNewMap, Unevaluated[Sequence[]]]]

You could also use a wrapper that removes everything that's not a Graphics or an option:

ShowValidOnly[a___] := Show@@Cases[{a}, (_Graphics | _Rule | _RuleDelayed)]
ShowValidOnly[grPacing, grAcq, grNewMap]
share|improve this answer
    
Is there a reason one would not simply use Show[p1, p2, {}]? What am I missing? Also, you could replace Unevaluated[Sequence[]] with ##&[]. –  Mr.Wizard Apr 17 '13 at 9:46
    
I understand.Thank you all! –  Liad Apr 17 '13 at 10:08
3  
@Mr.Wizard That's great for cases where your plot function will return either a valid graphics or {}, but in the general case it's nice to be able to perform an arbitrary check. Though you could replace Unevaluated[Sequence[]] with {}. That's just my personal preference. –  jVincent Apr 17 '13 at 10:13

Another approach is to use DeleteCases. In this example, where you wish to remove Null, you could use

 Show[  ...   DeleteCases[ graphicStuff , Null]   ... ] 

and then Show will be happy.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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