Thanks, I think you are right about the datetimes for the x axis causing
the problem.
Does anyone have any ideas how to resolve this?

On Thu, Nov 3, 2011 at 4:11 AM, Benjamin Root <ben.r...@ou.edu> wrote:

> I have seen situations when using datetimes for the x axis where if all
> the data being viewed is masked (or nans, or whatever) then it errors out
> because the axis range can't be determined.  Maybe that is what is
> happening here?
>
> Ben Root
>
>
> On Wed, Nov 2, 2011 at 11:48 AM, Michael Droettboom <md...@stsci.edu>wrote:
>
>>  matplotlib should handle both masked arrays and arrays with NaNs and
>> treat both the same.  Can you reduce the script to something that can be
>> run independently without data?  It's not clear to me yet why this is
>> failing.
>>
>> Mike
>>
>>
>> On 11/01/2011 05:24 PM, questions anon wrote:
>>
>> Hi All,
>> I am trying to plot time against mean daily temperature values. The
>> problem is temperature contains no data in a few areas. I want to be able
>> to ignore this and continue plotting.
>> When I run the below script on my data that has all normal numbers it
>> works fine but when I run the script on my data that has sections of 'no
>> data' I receive the below error and the graph will not plot the trendline.
>> Any suggestions on how I could fix this.
>> Thanks
>>
>> *Warning (from warnings module):
>>   File "C:\Python27\lib\site-packages\numpy\ma\core.py", line 3785
>>     warnings.warn("Warning: converting a masked element to nan.")
>> UserWarning: Warning: converting a masked element to nan.*
>>
>>
>> from netCDF4 import Dataset
>> import matplotlib.pyplot as plt
>> import numpy as N
>> from mpl_toolkits.basemap import Basemap
>> from netcdftime import utime
>> from datetime import datetime
>> import os
>> from numpy import *
>> import matplotlib.dates as mdates
>> from numpy import ma as MA
>>
>> TSFCmeanall=[]
>> timeall=[]
>> time_intall=[]
>>
>> MainFolder=r"E:/GriddedData/T_SFC/1987/"
>> for (path, dirs, files) in os.walk(MainFolder):
>>                         for dir in dirs:
>>                                 print dir
>>                         path=path+'/'
>>
>>                         for ncfile in files:
>>                                 if ncfile[-3:]=='.nc':
>>                                     ncfile=os.path.join(path,ncfile)
>>                                     ncfile=Dataset(ncfile, 'r+',
>> 'NETCDF4')
>>                                     TSFC=ncfile.variables['T_SFC'][0:20]
>>                                     TIME=ncfile.variables['time'][0:20]
>>
>> fillvalue=ncfile.variables['T_SFC']._FillValue
>>                                     TSFC=MA.masked_values(TSFC, fillvalue)
>>                                     ncfile.close()
>>
>>                                     for TSFC, TIME in
>> zip((TSFC[:]),(TIME[:])):
>>                                         cdftime=utime('seconds since
>> 1970-01-01 00:00:00')
>>                                         ncfiletime=cdftime.num2date(TIME)
>>                                         timestr=str(ncfiletime)
>>                                         d = datetime.strptime(timestr,
>> '%Y-%m-%d %H:%M:%S')
>>                                         date_string =
>> d.strftime('%Y%m%d%H')
>>                                         time_int=int(date_string)
>>
>>                                         TSFCmean=N.mean(TSFC)
>>
>>                                         TSFCmeanall.append(TSFCmean)
>>                                         timeall.append(ncfiletime)
>>                                         time_intall.append(time_int)
>>
>> x=timeall
>> y=TSFCmeanall
>> x2=time_intall
>>
>> fig, ax=plt.subplots(1)
>>
>> z=N.polyfit(x2,y,1)
>> p=N.poly1d(z)
>>
>> plt.plot(x,y)
>> plt.plot(x,p(x2),'r--') #add trendline to plot
>>
>> fig.autofmt_xdate()
>> ax.fmt_xdata=mdates.DateFormatter('%Y-%m-%d %H:%M:%S')
>> plt.ylabel("Temperature C")
>> plt.title("Mean Daily Temp")
>> plt.show()
>>
>>
>>
>>
>>
>>
>>
>>
>> ------------------------------------------------------------------------------
>> RSA&#174; Conference 2012
>> Save $700 by Nov 18
>> Register now&#33;http://p.sf.net/sfu/rsa-sfdev2dev1
>>
>>
>>
>> _______________________________________________
>> Matplotlib-users mailing 
>> listMatplotlib-users@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>
>>
>>
>>
>> ------------------------------------------------------------------------------
>> RSA&#174; Conference 2012
>> Save $700 by Nov 18
>> Register now&#33;
>> http://p.sf.net/sfu/rsa-sfdev2dev1
>> _______________________________________________
>> Matplotlib-users mailing list
>> Matplotlib-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>
>>
>
>
> ------------------------------------------------------------------------------
> RSA&#174; Conference 2012
> Save $700 by Nov 18
> Register now&#33;
> http://p.sf.net/sfu/rsa-sfdev2dev1
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to