[Yt-svn] yt-commit r1685 - trunk/yt/raven

mturk at wrangler.dreamhost.com mturk at wrangler.dreamhost.com
Thu Apr 8 20:05:44 PDT 2010


Author: mturk
Date: Thu Apr  8 20:05:43 2010
New Revision: 1685
URL: http://yt.enzotools.org/changeset/1685

Log:
Adding a scatter plot that accepts a data source.  Currently it does not
(directly) color by another field.



Modified:
   trunk/yt/raven/PlotCollection.py
   trunk/yt/raven/PlotTypes.py

Modified: trunk/yt/raven/PlotCollection.py
==============================================================================
--- trunk/yt/raven/PlotCollection.py	(original)
+++ trunk/yt/raven/PlotCollection.py	Thu Apr  8 20:05:43 2010
@@ -436,6 +436,19 @@
         p["Axis"] = None
         return p
 
+    def add_scatter_source(self, data_source, fields, id=None,
+                    axes = None, figure = None, plot_options = None):
+        """
+        Given a *data_source*, and *fields*, plot a scatter plot.
+        *plot_options* are sent to the scatter command.
+        """
+        if id is None: id = self._get_new_id()
+        sp = PlotTypes.ScatterPlot(data_source, fields, id,
+                                   plot_options = plot_options,
+                                   figure=figure, axes=axes)
+        p = self._add_plot(sp)
+        return p
+
     def add_fixed_resolution_plot(self, frb, field, center=None, use_colorbar=True,
                       figure = None, axes = None, fig_size=None, **kwargs):
         p = self._add_plot(PlotTypes.FixedResolutionPlot(frb, field,

Modified: trunk/yt/raven/PlotTypes.py
==============================================================================
--- trunk/yt/raven/PlotTypes.py	(original)
+++ trunk/yt/raven/PlotTypes.py	Thu Apr  8 20:05:43 2010
@@ -974,11 +974,11 @@
         else:
             self._log_y = False
 
-    def switch_x(self, field, weight="CellMassMsun", accumulation=False):
+    def switch_x(self, field):
         self.fields[0] = field
         self.axis_names["X"] = field
     
-    def switch_z(self, field, weight="CellMassMsun", accumulation=False):
+    def switch_z(self, field):
         self.fields[1] = field
         self.axis_names["Y"] = field
 
@@ -995,6 +995,29 @@
 
     switch_y = switch_z # Compatibility...
 
+class ScatterPlot(LineQueryPlot):
+    _type_name = "ScatterPlot"
+
+    def _redraw_image(self):
+        self._axes.clear()
+        self._axes.scatter(
+             self.data[self.fields[0]], self.data[self.fields[1]],
+             **self.plot_options)
+        xscale = {True: "log", False: "linear"}.get(self._log_x)
+        yscale = {True: "log", False: "linear"}.get(self._log_y)
+        self._axes.set_xscale(xscale)
+        self._axes.set_yscale(yscale)
+        self._autoset_label(self.fields[0], self._axes.set_xlabel)
+        self._autoset_label(self.fields[1], self._axes.set_ylabel)
+        self._run_callbacks()
+
+    # We override because we don't want to ditch our collections
+    def _run_callbacks(self):
+        self._axes.patches = []
+        self._axes.texts = []
+        for cb in self._callbacks:
+            cb(self)
+
 # Now we provide some convenience functions to get information about plots.
 # With Matplotlib 0.98.x, the 'transforms' branch broke backwards
 # compatibility.  Despite that, the various packagers are plowing ahead with



More information about the yt-svn mailing list