From 8d49747b34c3724228a345c2235b4b3ecb001aa6 Mon Sep 17 00:00:00 2001 From: John Hunter Date: Wed, 20 Jun 2007 14:23:17 +0000 Subject: [PATCH] cleaned up lineprops gtk svn path=/trunk/matplotlib/; revision=3402 --- examples/lineprops_dialog_gtk.py | 25 +++ examples/pick_event_demo3.py | 82 ------- lib/matplotlib/backends/backend_gtk.py | 40 +--- lib/matplotlib/lines.py | 51 +++-- lib/matplotlib/mlab.py | 5 +- lib/matplotlib/mpl-data/lineprops.glade | 285 ++++++++++++++++++++++++ setup.py | 1 + 7 files changed, 352 insertions(+), 137 deletions(-) create mode 100644 examples/lineprops_dialog_gtk.py delete mode 100644 examples/pick_event_demo3.py create mode 100644 lib/matplotlib/mpl-data/lineprops.glade diff --git a/examples/lineprops_dialog_gtk.py b/examples/lineprops_dialog_gtk.py new file mode 100644 index 000000000000..5e41900d930f --- /dev/null +++ b/examples/lineprops_dialog_gtk.py @@ -0,0 +1,25 @@ +import matplotlib +matplotlib.use('GTKAgg') +from matplotlib.backends.backend_gtk import DialogLineprops + +import numpy as npy +from pylab import figure, show + +def f(t): + s1 = npy.cos(2*npy.pi*t) + e1 = npy.exp(-t) + return npy.multiply(s1,e1) + +t1 = npy.arange(0.0, 5.0, 0.1) +t2 = npy.arange(0.0, 5.0, 0.02) +t3 = npy.arange(0.0, 2.0, 0.01) + +fig = figure() +ax = fig.add_subplot(111) +l1, = ax.plot(t1, f(t1), 'bo', label='line 1') +l2, = ax.plot(t2, f(t2), 'k--', label='line 2') + +dlg = DialogLineprops([l1,l2]) +dlg.show() +show() + diff --git a/examples/pick_event_demo3.py b/examples/pick_event_demo3.py deleted file mode 100644 index f19d761c3175..000000000000 --- a/examples/pick_event_demo3.py +++ /dev/null @@ -1,82 +0,0 @@ -import numpy as npy -from pylab import figure, show - - -X = npy.random.rand(100, 200) -xs = npy.mean(X, axis=1) -ys = npy.std(X, axis=1) - -fig = figure() -ax = fig.add_subplot(211) -ax.set_title('click on point to plot time series') -line, = ax.plot(xs, ys, 'o', picker=5) # 5 points tolerance -ax2 = fig.add_subplot(212) - -class PointBrowser: - """ - Click on a point to select and highlight it -- the data that - generated the point will be shown in the lower axes. Use the 'n' - and 'p' keys to browse through the next and pervious points - """ - def __init__(self): - self.lastind = 0 - - self.text = ax.text(0.05, 0.95, 'selected: none', - transform=ax.transAxes, va='top') - self.selected, = ax.plot([xs[0]], [ys[0]], 'o', ms=12, alpha=0.4, - color='yellow', visible=False) - - def onpress(self, event): - if self.lastind is None: return - if event.key not in ('n', 'p'): return - if event.key=='n': inc = 1 - else: inc = -1 - - - self.lastind += inc - self.lastind = npy.clip(self.lastind, 0, len(xs)-1) - self.update() - - def onpick(self, event): - - if event.artist!=line: return True - - N = len(event.ind) - if not N: return True - - # the click locations - x = event.mouseevent.xdata - y = event.mouseevent.ydata - - - distances = npy.hypot(x-xs[event.ind], y-ys[event.ind]) - indmin = distances.argmin() - dataind = event.ind[indmin] - - self.lastind = dataind - self.update() - - def update(self): - if self.lastind is None: return - - dataind = self.lastind - - ax2.cla() - ax2.plot(X[dataind]) - - ax2.text(0.05, 0.9, 'mu=%1.3f\nsigma=%1.3f'%(xs[dataind], ys[dataind]), - transform=ax2.transAxes, va='top') - ax2.set_ylim(-0.5, 1.5) - self.selected.set_visible(True) - self.selected.set_data(xs[dataind], ys[dataind]) - - self.text.set_text('selected: %d'%dataind) - fig.canvas.draw() - - -browser = PointBrowser() - -fig.canvas.mpl_connect('pick_event', browser.onpick) -fig.canvas.mpl_connect('key_press_event', browser.onpress) - -show() diff --git a/lib/matplotlib/backends/backend_gtk.py b/lib/matplotlib/backends/backend_gtk.py index c11e041d8d63..5d8b56a3875d 100644 --- a/lib/matplotlib/backends/backend_gtk.py +++ b/lib/matplotlib/backends/backend_gtk.py @@ -27,6 +27,8 @@ def fn_name(): return sys._getframe(1).f_code.co_name where, transpose, nonzero, indices, ones, nx from matplotlib.widgets import SubplotTool +from matplotlib import lines +from matplotlib import cbook backend_version = "%d.%d.%d" % gtk.pygtk_version @@ -1096,47 +1098,17 @@ class DialogLineprops: 'on_dialog_lineprops_cancelbutton_clicked', ) - linestyles = ( - '-' , - '--' , - '-.' , - ',' , - 'steps', - 'None' , - ) - + linestyles = [ls for ls in lines.Line2D.lineStyles if ls.strip()] linestyled = dict([ (s,i) for i,s in enumerate(linestyles)]) - markers = ( - 'None', - '.' , - ',' , - 'o' , - 'v' , - '^' , - '<' , - '>' , - '1' , - '2' , - '3' , - '4' , - 's' , - 'p' , - 'h' , - 'H' , - '+' , - 'x' , - 'D' , - 'd' , - '|' , - '_' , - ) + markers = [m for m in lines.Line2D.markers if cbook.is_string_like(m)] markerd = dict([(s,i) for i,s in enumerate(markers)]) def __init__(self, lines): - + import gtk.glade + datadir = matplotlib.get_data_path() gladefile = os.path.join(datadir, 'lineprops.glade') if not os.path.exists(gladefile): diff --git a/lib/matplotlib/lines.py b/lib/matplotlib/lines.py index 61da0c65e13c..345104634209 100644 --- a/lib/matplotlib/lines.py +++ b/lib/matplotlib/lines.py @@ -73,7 +73,7 @@ def unmasked_index_ranges(mask, compressed = True): class Line2D(Artist): - _lineStyles = { + lineStyles = _lineStyles = { # hidden names deprecated '-' : '_draw_solid', '--' : '_draw_dashed', '-.' : '_draw_dash_dot', @@ -84,7 +84,7 @@ class Line2D(Artist): '' : '_draw_nothing', } - _markers = { + markers = _markers = { # hidden names deprecated '.' : '_draw_point', ',' : '_draw_pixel', 'o' : '_draw_circle', @@ -435,14 +435,7 @@ def draw(self, renderer): gc = renderer.new_gc() self._set_gc_clip(gc) - if (is_string_like(self._markeredgecolor) and - self._markeredgecolor == 'auto'): - if self._marker in self.filled_markers: - gc.set_foreground('k') - else: - gc.set_foreground(self._color) - else: - gc.set_foreground(self._markeredgecolor) + gc.set_foreground(self.get_markeredgecolor()) gc.set_linewidth(self._markeredgewidth) gc.set_alpha(self._alpha) funcname = self._markers.get(self._marker, '_draw_nothing') @@ -457,9 +450,33 @@ def get_linestyle(self): return self._linestyle def get_linewidth(self): return self._linewidth def get_marker(self): return self._marker - def get_markeredgecolor(self): return self._markeredgecolor + + def get_markeredgecolor(self): + if (is_string_like(self._markeredgecolor) and + self._markeredgecolor == 'auto'): + if self._marker in self.filled_markers: + return 'k' + else: + return self._color + else: + return self._markeredgecolor + + + return self._markeredgecolor def get_markeredgewidth(self): return self._markeredgewidth - def get_markerfacecolor(self): return self._markerfacecolor + + def get_markerfacecolor(self): + if (self._markerfacecolor is None or + (is_string_like(self._markerfacecolor) and + self._markerfacecolor.lower()=='none') ): + return self._markerfacecolor + elif (is_string_like(self._markerfacecolor) and + self._markerfacecolor.lower() == 'auto'): + return self._color + else: + return self._markerfacecolor + + def get_markersize(self): return self._markersize def get_xdata(self, orig=True): @@ -1136,15 +1153,11 @@ def update_from(self, other): def _get_rgb_face(self): - if (self._markerfacecolor is None or - (is_string_like(self._markerfacecolor) and - self._markerfacecolor.lower()=='none') ): + facecolor = self.get_markerfacecolor() + if is_string_like(facecolor) and facecolor.lower()=='none': rgbFace = None - elif (is_string_like(self._markerfacecolor) and - self._markerfacecolor.lower() == 'auto'): - rgbFace = colorConverter.to_rgb(self._color) else: - rgbFace = colorConverter.to_rgb(self._markerfacecolor) + rgbFace = colorConverter.to_rgb(facecolor) return rgbFace # some aliases.... diff --git a/lib/matplotlib/mlab.py b/lib/matplotlib/mlab.py index 214091e3cb90..fcb11a165636 100644 --- a/lib/matplotlib/mlab.py +++ b/lib/matplotlib/mlab.py @@ -1365,7 +1365,7 @@ def load(fname,comments='#',delimiter=None, converters=None,skiprows=0, else: return X def csv2rec(fname, comments='#', skiprows=0, checkrows=5, delimiter=',', - converterd=None, names=None): + converterd=None, names=None, missing=None): """ Load data from comma/space/tab delimited file in fname into a numpy record array and return the record array. @@ -1446,7 +1446,8 @@ def get_converters(reader): if func is None: if not item.strip(): continue func = converters[j] - func = get_func(item, func) + if len(item.strip()): + func = get_func(item, func) converters[j] = func return converters diff --git a/lib/matplotlib/mpl-data/lineprops.glade b/lib/matplotlib/mpl-data/lineprops.glade new file mode 100644 index 000000000000..d731f3370bb7 --- /dev/null +++ b/lib/matplotlib/mpl-data/lineprops.glade @@ -0,0 +1,285 @@ + + + + + + + True + Line Properties + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + True + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + True + -6 + + + + + + + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + True + -5 + + + + + + 0 + False + True + GTK_PACK_END + + + + + + True + False + 0 + + + + True + + + + + 0 + True + True + + + + + + True + 0 + 0.5 + GTK_SHADOW_NONE + + + + True + 0.5 + 0.5 + 1 + 1 + 0 + 0 + 12 + 0 + + + + True + False + 0 + + + + True + 2 + 3 + False + 0 + 0 + + + + True + Marker + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + 1 + 1 + 2 + fill + + + + + + + True + + + + + 1 + 2 + 0 + 1 + fill + + + + + + True + + + + + 1 + 2 + 1 + 2 + fill + fill + + + + + + True + True + True + Line color + True + + + + 2 + 3 + 0 + 1 + fill + + + + + + + True + True + False + Marker color + True + + + + 2 + 3 + 1 + 2 + fill + + + + + + + True + Line style + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + 1 + 0 + 1 + fill + + + + + + 0 + True + True + + + + + + + + + + True + <b>Line properties</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + label_item + + + + + 0 + True + True + + + + + 0 + True + True + + + + + + + diff --git a/setup.py b/setup.py index eb1531732482..b84a9e332e53 100644 --- a/setup.py +++ b/setup.py @@ -99,6 +99,7 @@ 'mpl-data/images/*.png', 'mpl-data/images/*.ppm', 'mpl-data/matplotlibrc', + 'mpl-data/*.glade', 'backends/Matplotlib.nib/*', ]}