← Back to team overview

aesthete-team team mailing list archive

Re: Plot patch to change data limits

 

Chris Palmer wrote:
Hi all,

Please review this patch which adds the ability to change the data
limits in Glancer, allowing for instance a (slightly) more meaningful
plot of cos(𝛉) and the like.

(Yes, I'm flitting between areas!)

Regards,

Chris.



Okay, another patch, which allows one to set the resolution of the Glancer window. All plots within that Glancer window share this resolution, but (hopefully) plots in other Glancer windows do not. It seems a bit messy but it's the best I could come up with.

Let me know what you think.

Chris.


=== modified file 'aesthete/glancer/Plot.py'
--- aesthete/glancer/Plot.py	2011-11-15 06:30:46 +0000
+++ aesthete/glancer/Plot.py	2011-11-17 03:34:24 +0000
@@ -203,10 +203,12 @@
             self.queue_draw()
 
     def load_series(self, source, series = None, vals = None):
+        resolution = self.get_resolution()
         if source is None :
             mpl_line, = self.axes.plot(series, vals)
             line = GlancerLine(self, line=mpl_line, env=self.get_aenv())
         elif source.source_type() == 'line' :
+            source.source_set_resolution(resolution)
             line = GlancerLine(self, source=source, axes=self.axes,
                            read_series=self.read_series,
                            env=self.get_aenv())
@@ -227,7 +229,11 @@
              'figure_facecolor' : [self.change_figure_facecolor, self.get_figure_facecolor, True],
              'axes_axis_bgcolor' : [self.change_axes_axis_bgcolor, self.get_axes_axis_bgcolor, True],
              'axes_xlabel' : [self.change_axes_xlabel, self.get_axes_xlabel, True],
+             'axes_xmin' : [self.change_axes_xmin, self.get_axes_xmin, True],
+             'axes_xmax' : [self.change_axes_xmax, self.get_axes_xmax, True],
              'axes_ylabel' : [self.change_axes_ylabel, self.get_axes_ylabel, True],
+             'axes_ymin' : [self.change_axes_ymin, self.get_axes_ymin, True],
+             'axes_ymax' : [self.change_axes_ymax, self.get_axes_ymax, True],
              'title_font' : [self.change_title_font, self.get_title_font, True],
              'xlabel_font' : [self.change_xlabel_font, self.get_xlabel_font, True],
              'ylabel_font' : [self.change_ylabel_font, self.get_ylabel_font, True],
@@ -239,7 +245,8 @@
              'ymultiplier' : [self.change_ymultiplier, self.get_ymultiplier, True],
              'read_series' : [self.change_read_series, self.get_read_series, True],
              'legend_loc' : [self.change_legend_loc, self.get_legend_loc, True],
-             'title' : [self.change_title, self.get_title, True] }
+             'title' : [self.change_title, self.get_title, True],
+             'resolution' : [self.change_resolution, self.get_resolution, True] }
     #BEGIN PROPERTIES FUNCTIONS
     def get_xmultiplier(self, val=None) : return 1. if val==None else float(val)
     def get_ymultiplier(self, val=None) : return 1. if val==None else float(val)
@@ -247,6 +254,10 @@
     def get_legend(self, val=None): return self.legend if val==None else (val=='True')
     def get_read_series(self, val=None): return self.read_series if val==None else (val=='True')
     def get_title(self, val=None): return self.title if val==None else val
+    def get_resolution(self, val=None) :
+        if self.lines == [] :
+            return 10
+        return self.lines[0].source.source_get_resolution() if val==None else val
     def get_legend_loc(self, val=None) :
         return (legend_locs_rev[self.legend_object.get_loc()] if self.legend_object else '')\
         if val==None else val
@@ -257,7 +268,11 @@
         return mpl_to_tuple(self.fig.get_facecolor()) \
         if val==None else string_to_float_tup(val)
     def get_axes_xlabel(self, val=None) : return self.axes.get_xlabel() if val==None else val
+    def get_axes_xmin(self, val=None) : return self.axes.get_xlim()[0] if val==None else val
+    def get_axes_xmax(self, val=None) : return self.axes.get_xlim()[1] if val==None else val
     def get_axes_ylabel(self, val=None) : return self.axes.get_ylabel() if val==None else val
+    def get_axes_ymin(self, val=None) : return self.axes.get_ylim()[0] if val==None else val
+    def get_axes_ymax(self, val=None) : return self.axes.get_ylim()[1] if val==None else val
     def get_xhide_oom(self, val=None) :
         return False \
         if val==None else (val=='True')
@@ -290,6 +305,10 @@
         self.title = val
         self.axes.set_title(self.title, visible = (self.title!=''))
         self.queue_draw()
+    def change_resolution(self, val) :
+        for line in self.lines : 
+            line.source.source_set_resolution(float(val))
+        self.queue_draw()
     def change_xhide_oom(self, val) : 
         self.axes.get_xaxis().major.formatter.hide_oom = val
         self.queue_draw()
@@ -324,7 +343,11 @@
     def change_legend(self, val) : self.legend = val; self.do_legend()
     def change_axes_axis_bgcolor(self, val) : self.axes.set_axis_bgcolor(val); self.queue_draw()
     def change_axes_xlabel(self, val) : self.axes.set_xlabel(val); self.queue_draw()
+    def change_axes_xmin(self, val) : self.axes.set_xlim(left=float(val)); self.queue_draw()
+    def change_axes_xmax(self, val) : self.axes.set_xlim(right=float(val)); self.queue_draw()
     def change_axes_ylabel(self, val) : self.axes.set_ylabel(val); self.queue_draw()
+    def change_axes_ymin(self, val) : self.axes.set_ylim(bottom=float(val)); self.queue_draw()
+    def change_axes_ymax(self, val) : self.axes.set_ylim(top=float(val)); self.queue_draw()
     def change_figure_facecolor(self, val) : self.fig.set_facecolor(val); self.queue_draw()
     #END PROPERTIES FUNCTIONS
 
@@ -414,6 +437,9 @@
         general_table_maker.append_heading("Colours")
         general_table_maker.append_row("Face", self.aes_method_colour_button("figure_facecolor", "Set figure colour"))
         general_table_maker.append_row("Axes",self.aes_method_colour_button("axes_axis_bgcolor", "Axes Background Colour"))
+        general_table_maker.append_heading("Detail")
+        general_table_maker.append_row("Resolution",
+            self.aes_method_entry_update("resolution", "Set"))
 
         config_tabl = general_table_maker.make_table()
         config_tabl_vbox = gtk.VBox(); config_tabl_vbox.pack_start(config_tabl, False)
@@ -444,6 +470,11 @@
             axes_table_maker.append_row(" Axis",
                 self.aes_method_font_button(axis+"label_font", "Set "+axes[axis]+" axis font"))
             axes_table_maker.append_row(" Tick", self.aes_method_font_button(axis+"tick_font", "Set "+axes[axis]+" axis font"))
+            axes_table_maker.append_heading("Data Limits")
+            axes_table_maker.append_row(" Minimum Value",
+                self.aes_method_entry_update("axes_"+axis+"min", "Set"))
+            axes_table_maker.append_row(" Maximum Value",
+                self.aes_method_entry_update("axes_"+axis+"max", "Set"))
 
             config_tabl = axes_table_maker.make_table()
             config_tabl_vbox = gtk.VBox(); config_tabl_vbox.pack_start(config_tabl, False); 

=== modified file 'aesthete/sources/Source.py'
--- aesthete/sources/Source.py	2011-11-05 03:06:00 +0000
+++ aesthete/sources/Source.py	2011-11-17 03:41:44 +0000
@@ -38,7 +38,7 @@
 
     def __init__(self, stem, function, arg_count, env = None, show = False,
                  reloadable = False, resolution = 10) :
-        self.resolution = resolution
+        self.resolution = resolution 
         self.function = function
         self.max_dim = arg_count
         Source.__init__(self, stem, env, show, reloadable, needs_x_range=True)
@@ -73,6 +73,15 @@
     def source_get_max_dim(self) :
         return self.max_dim
 
+    def source_get_resolution(self) :
+        return self.resolution
+
+    def source_set_resolution(self, resolution = None) :
+        if resolution is None :
+            self.resolution = 10
+        else :
+            self.resolution = resolution
+
 class CSV (Source) :
     vals = None
     dim = 2


Follow ups

References