I am writing a notebook in which ListPlot is used to plot a list of 3 data lists. At least one of the data lists is non-empty. Any non-empty data list consists of a list of pairs. So this is a common application of plotting multiple data sets on a single graph.
The issue is that the data sets are derived from earlier processing in such a manner that either or both of the second and third list can be empty. Then I would just like Mathematica to plot the non-empty sets. I had hoped this would be straightforward. When I plot an empty list with ListPlot, I just get an empty plot. So far so good. But when I plot a list of lists in which contains an empty list, I get an error. Unless I find a way to solve this, the notebook must take on added complexity to account for the 4 possibilities. I can't just strip out the empty lists, since their identity is important and corresponds to a legend.
Does anyone see a nice way to do this? Some test code is below: (remove semicolons to get plots )
In[1]:= (* some data *)
d = Table[{n, Log[n]}, {n, 1, 100, 10}] // N;
In[2]:= (* it plots fine *)
ListPlot[d];
In[3]:= (* here ListPlot has an empty list, so it plots nothing *)
ListPlot[{}];
In[4]:= (* but if ListPlot is asked to plot both a non-empty list and \
an empty list, it generates an error *)
ListPlot[{d, {}}]
During evaluation of In[4]:= ListPlot::lpn: {<<1>>,{}} is not a list of numbers or pairs of numbers. >>
Out[4]= ListPlot[{{{1., 0.}, {11., 2.3979}, {21., 3.04452}, {31.,
3.43399}, {41., 3.71357}, {51., 3.93183}, {61., 4.11087}, {71.,
4.26268}, {81., 4.39445}, {91., 4.51086}}, {}}]
In[5]:= (* but if ListPlot is asked to plot both a non-empty list and \
an empty list, it generates an error *)
ListPlot[{d, {{}}}]
During evaluation of In[5]:= ListPlot::lpn: {<<1>>,{{}}} is not a list of numbers or pairs of numbers. >>
Out[5]= ListPlot[{{{1., 0.}, {11., 2.3979}, {21., 3.04452}, {31.,
3.43399}, {41., 3.71357}, {51., 3.93183}, {61., 4.11087}, {71.,
4.26268}, {81., 4.39445}, {91., 4.51086}}, {{}}}]