diff climate_stripes.py @ 2:abdc27e01dca draft default tip

planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit e4c144851549600ffde5bcf875304d5edd98e2b1
author climate
date Sat, 09 Jul 2022 09:02:01 +0000
parents c6f2435d680b
children
line wrap: on
line diff
--- a/climate_stripes.py	Tue Apr 14 15:08:10 2020 -0400
+++ b/climate_stripes.py	Sat Jul 09 09:02:01 2022 +0000
@@ -72,7 +72,10 @@
             self.plot_format = plot_format.replace('X', '%')
 
     def read_data(self):
-        self.data = pd.read_csv(self.input, sep='\t')
+        if self.xname is not None:
+            self.data = pd.read_csv(self.input, sep='\t', index_col=self.xname, infer_datetime_format=True)
+        else:
+            self.data = pd.read_csv(self.input, sep='\t')
 
     def create_stripes(self):
         data = np.zeros((2, self.data[self.valname].shape[0]), dtype='float')
@@ -86,16 +89,11 @@
                    vmax=self.data[self.valname].quantile(q=0.99))
         if self.title:
             plt.title(self.title)
-        if self.xname:
+        if self.xname is not None:
             nrange = self.data.index.values
-            n = int(np.floor((nrange.max() - nrange.min())/int(self.nxsplit)))
-            date_list = self.data[self.xname].loc[::n].apply(
-                             lambda x: pd.to_datetime(str(x),
-                                                      format=self.format))
+            date_list = pd.to_datetime(nrange[::int(self.nxsplit)], format=self.format)
             date_list = [i.strftime(self.plot_format) for i in date_list]
-            nval = int(self.data[self.xname].loc[::n].shape[0])
-            ax.xaxis.set_major_locator(plt.MaxNLocator(nval))
-            ax.xaxis.set_ticklabels(date_list)
+            ax.set_xticks(np.arange(0, len(nrange), int(self.nxsplit)), date_list)
             ax.xaxis.set_tick_params(rotation=45)
         else:
             ax.set_xticks([])