# How to programmatically control which plot to display with LogLinearPlot

LogLinearPlot is capable of plotting multiple functions in the same graph.

ex. LogLinearPlot[{graph1[w], graph2[w]}, {w, 1, 100}]

Is there a way to select automatically whether both graph1 and graph2 are executed? The reason is that in my code, I have certain conditions under which graph1 and/or graph2 would actually exist. In the case where one of the graphs does not exist, I get problems with the plotting.

• what version you are using? in V10 this will works fine: g1[w_] := Erf[w]; LogLinearPlot[{g1[w], g2[w]}, {w, 1, 100}] – Algohi Dec 6 '14 at 0:48

Just make sure that in the invalid region the function doesn't evaluate to anything numerical. For example,

Plot[{If[x < 0.5, Sin[x]], If[x > -0.5, x^2]}, {x, -2, 2}] You can check whether a plot is empty or not with

FullForm[expr]

ploA = Plot[{Sin[x]}, {x, -1, 1}];
ploB = Plot[{Cos[]}, {x, -1, 1}];
FullForm[ploB] ploB[] == {}
(* True *)


With this Strategy you can check if your plots are empty:

ploA = Plot[{Sin[x]}, {x, -1, 1}][] == {}
(* False *)

ploB = Plot[{Cos[]}, {x, -1, 1}][] == {}
(* True *)


As shown by @Szabolcs You can use the If statement and control plots according to your needs:

f1[x_] := Sin[x]
f2[x_] := Cos[x]
Plot[{If[ploA == False, f1[x]], If[ploB == False, f2[x]]}, {x, -2, 2}] ploB = Plot[{Cos[x]}, {x, -1, 1}][] == {}
(* False *)

Plot[{If[ploA == False, f1[x]], If[ploB == False, f2[x]]}, {x, -2, 2}] 