comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Completely omit NaNs from line plot
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Completely omit NaNs from line plot [message #93266] Tue, 24 May 2016 17:19 Go to next message
laura.hike is currently offline  laura.hike
Messages: 87
Registered: September 2013
Member
Hi,

I have some solar irradiance data. All the nighttime values are set to NaN so that they won't be used in any calculations. I would like to plot a section of the time series but not include any of the points that are NaNs. That is, normally plot won't make any mark for the time when there is a NaN, but I want to completely skip these points because they just make the plot twice as long as necessary. Is there any way to do this other than creating a new array without those points?

Thanks,

Laura
Re: Completely omit NaNs from line plot [message #93267 is a reply to message #93266] Wed, 25 May 2016 01:05 Go to previous messageGo to next message
Mats Löfdahl is currently offline  Mats Löfdahl
Messages: 263
Registered: January 2012
Senior Member
Den onsdag 25 maj 2016 kl. 02:19:40 UTC+2 skrev laura...@gmail.com:
> Hi,
>
> I have some solar irradiance data. All the nighttime values are set to NaN so that they won't be used in any calculations. I would like to plot a section of the time series but not include any of the points that are NaNs. That is, normally plot won't make any mark for the time when there is a NaN, but I want to completely skip these points because they just make the plot twice as long as necessary. Is there any way to do this other than creating a new array without those points?
>
> Thanks,
>
> Laura

If you plot with time on the horizontal axis, the plot will be the same length whether you remove the NaNs or not, right? If you don't care about the time axis, you could always do something like

plot, data(where(finite(data)))
Re: Completely omit NaNs from line plot [message #93269 is a reply to message #93267] Wed, 25 May 2016 11:48 Go to previous messageGo to next message
dg86 is currently offline  dg86
Messages: 118
Registered: September 2012
Senior Member
On Wednesday, May 25, 2016 at 4:05:33 AM UTC-4, Mats Löfdahl wrote:
> Den onsdag 25 maj 2016 kl. 02:19:40 UTC+2 skrev laura...@gmail.com:
>> Hi,
>>
>> I have some solar irradiance data. All the nighttime values are set to NaN so that they won't be used in any calculations. I would like to plot a section of the time series but not include any of the points that are NaNs. That is, normally plot won't make any mark for the time when there is a NaN, but I want to completely skip these points because they just make the plot twice as long as necessary. Is there any way to do this other than creating a new array without those points?
>>
>> Thanks,
>>
>> Laura
>
> If you plot with time on the horizontal axis, the plot will be the same length whether you remove the NaNs or not, right? If you don't care about the time axis, you could always do something like
>
> plot, data(where(finite(data)))

plot, data[where(finite(data))]

"modernized" the array notation to emphasize subscripting by where().

TTFN,

David
Re: Completely omit NaNs from line plot [message #93270 is a reply to message #93269] Thu, 26 May 2016 01:39 Go to previous messageGo to next message
Markus Schmassmann is currently offline  Markus Schmassmann
Messages: 129
Registered: April 2016
Senior Member
On 05/25/2016 08:48 PM, David Grier wrote:
> On Wednesday, May 25, 2016 at 4:05:33 AM UTC-4, Mats Löfdahl wrote:
>> Den onsdag 25 maj 2016 kl. 02:19:40 UTC+2 skrev
>> laura...@gmail.com:
>>> I have some solar irradiance data. All the nighttime values are
>>> set to NaN so that they won't be used in any calculations. I
>>> would like to plot a section of the time series but not include
>>> any of the points that are NaNs. That is, normally plot won't
>>> make any mark for the time when there is a NaN, but I want to
>>> completely skip these points because they just make the plot
>>> twice as long as necessary. Is there any way to do this other
>>> than creating a new array without those points?
>> If you plot with time on the horizontal axis, the plot will be the
>> same length whether you remove the NaNs or not, right? If you don't
>> care about the time axis, you could always do something like
> plot, data[where(finite(data))]
Mats' solution with David's better notation probably does what you want,
although it does create an array without those points.

Id you really want to avoid that, try this:

time=make_array(n_elements(data),/ulong)
wf=where(finite(data),cnt)
time[wf]=ulindgen(cnt)
p=plot(time, data)

This also uses the plot function instead of plot procedure, the latter i
would no longer use.
Re: Completely omit NaNs from line plot [message #93271 is a reply to message #93270] Thu, 26 May 2016 02:30 Go to previous message
dg86 is currently offline  dg86
Messages: 118
Registered: September 2012
Senior Member
On Thursday, May 26, 2016 at 4:39:12 AM UTC-4, Markus Schmassmann wrote:
> On 05/25/2016 08:48 PM, David Grier wrote:
>> On Wednesday, May 25, 2016 at 4:05:33 AM UTC-4, Mats Löfdahl wrote:
>>> Den onsdag 25 maj 2016 kl. 02:19:40 UTC+2 skrev
>>> laura...@gmail.com:
>>>> I have some solar irradiance data. All the nighttime values are
>>>> set to NaN so that they won't be used in any calculations. I
>>>> would like to plot a section of the time series but not include
>>>> any of the points that are NaNs. That is, normally plot won't
>>>> make any mark for the time when there is a NaN, but I want to
>>>> completely skip these points because they just make the plot
>>>> twice as long as necessary. Is there any way to do this other
>>>> than creating a new array without those points?
>>> If you plot with time on the horizontal axis, the plot will be the
>>> same length whether you remove the NaNs or not, right? If you don't
>>> care about the time axis, you could always do something like
>> plot, data[where(finite(data))]
> Mats' solution with David's better notation probably does what you want,
> although it does create an array without those points.
>
> Id you really want to avoid that, try this:
>
> time=make_array(n_elements(data),/ulong)
> wf=where(finite(data),cnt)
> time[wf]=ulindgen(cnt)
> p=plot(time, data)
>
> This also uses the plot function instead of plot procedure, the latter i
> would no longer use.

If the goal is to omit the NANs without leaving gaps in the plot, then the
solution would be

time = findgen(n_elements(data))
w = where(finite(data))
p = plot(time[w], data[w])

This uses the indexes of the finite data points to select points from the
time array that correspond to the valid data points.
Markus' proposed solution creates a time array consisting of consecutive times,
which might not be what you want.

A simpler version of Markus' solution is

w = where(finite(data), count)
time = findgen(count)
p = plot(time, data[w])

All the best,

David
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: IDL Morph structuring element
Next Topic: Adding line to a barplot

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:47:33 PDT 2025

Total time taken to generate the page: 0.00510 seconds