Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To check if plot empty in Mathematica

Is there a way in Mathematica to check whether a plot is empty or not?

By empty, I mean it is only showing the axes and not any data points. I have a function that, depending on its inputs, gives some data points (to be plotted later) or none, but i won't know whether it will produce any valid data points unless i plot it. And if it doesn't, when i plot it, it will return an empty plot. I would like to differentiate between the empty plot and a plot with data points.

like image 672
darXider Avatar asked Nov 26 '25 14:11

darXider


1 Answers

I'll generate an empty Plot to explore the form.

empty = Plot[{}, {x, 0, 1}];
FullForm[%]

shows that Plot[] returns a Graphics object with two parts - 1.) the content, and 2.) the options. In this case the first is an empty List, so setting a condition like

empty[[1]] == {}

should return True for this particular type of emptiness. It'll work for other Plots

Plot3D[{}, {x, -3, 3}, {y, -2, 2}][[1]] == {}

True

but you might have to pick apart the FullForm of your example to be sure.

like image 169
Fred Klingener Avatar answered Dec 01 '25 20:12

Fred Klingener



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!