matplotlib - x-axis rotation on a 6-subplots -


i bit stuck matplotilb subplot tools. here's i'm trying do: want 6 subplots displaying time-series of data. data (t1,t2,h1,h2...,time), lists.

my code follows:

fields={0:'air temperature (k)',1:'specific humidity',2:'sea surface  temperature (k)',3:'surface air pressure (hpa)',4:'wind (m.s-1)'}   fieldsfoam={0:t1,1:h1,2:sst1,3:p1,4:w1,5:astd1} fieldsostia={0:t2,1:h2,2:sst2,3:p2,4:w2,5:astd2}   plt.close()  f, ((ax1, ax2), (ax3, ax4),(ax5, ax6)) = plt.subplots(3, 2, sharex='col') ax={1:ax1,2:ax2,3:ax3,4:ax4,5:ax5,6:ax6} plt.ticklabel_format(useoffset=false)  plt.ticklabel_format(style='sci', axis='y', scilimits=(-3,3))  in range (1,7):      ax[i].plot(unit.num2date(time,'hours since 1970-01-01 00:00:00',  unit.calendar_standard),fieldsfoam[i-1])          ax[i].plot(unit.num2date(time,'hours since 1970-01-01 00:00:00', unit.calendar_standard),fieldsostia[i-1],color='r')     plt.setp(ax[i].get_xticklabels(), rotation=30, fontsize=0) 

i try

 plt.setp(plt.xticks()[1], rotation=45)  

but got same (long) error:

plt.setp(ax[i].get_xticklabels(), rotation=30, fontsize=10)     file "/usr/local/sci/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/axes.py", line 2614, in get_xticklabels     self.xaxis.get_ticklabels(minor=minor))    file "/usr/local/sci/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/axis.py", line 1161, in get_ticklabels     return self.get_majorticklabels()   file "/usr/local/sci/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/axis.py", line 1145, in get_majorticklabels     ticks = self.get_major_ticks()   file "/usr/local/sci/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/axis.py", line 1244, in get_major_ticks     numticks = len(self.get_major_locator()())   file "/usr/local/sci/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/dates.py", line 802, in __call__     self.refresh()   file "/usr/local/sci/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/dates.py", line 819, in refresh     dmin, dmax = self.viewlim_to_dt()   file "/usr/local/sci/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/dates.py", line 564, in viewlim_to_dt     return num2date(vmin, self.tz), num2date(vmax, self.tz)   file "/usr/local/sci/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/dates.py", line 311, in num2date     return _from_ordinalf(x, tz)   file "/usr/local/sci/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/dates.py", line 214, in _from_ordinalf     dt = datetime.datetime.fromordinal(ix) valueerror: ordinal must >= 1 

if not rotate dates, overlap. works fine, except rotation part.

if had ideas mistake(s) i'm doing, useful!

thanks flo


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -