[matplotlib-devel] Propose: dashed steps plot

2008-09-22 Thread Manuel Metz
Hi all,
  I think I have finally found a nice way to implement step-plots with
different linestyles. The way this is done required some re-writing of
lines.py, but I think it is done in a consistent manner:

  A new property *drawstyle* is introduced. By default this just
connects the datapoints by a straight line. It can be set to "steps-***"
to create step-plots. So, the important point is that "steps-***" is no
longer a linestyle and thus it is possible to set the linestyle
independently. Additionally one can set a combined line- and drawstyle,
e.g. linestyle='steps-mid:'.
  The drawstyle property has the advantage, that one can add other ways
to draw the data naturally, for example one can think of a drawstyle
"bspline" that connects data-points using a spline, or something like a
moving-mean plot.

  The patch is applied and also an example and its output. If there are
no objections, I will commit the patch soon.

Any comments ???

Manuel
Index: lines.py
===
--- lines.py	(revision 6115)
+++ lines.py	(working copy)
@@ -11,7 +11,8 @@
 from matplotlib import verbose
 import artist
 from artist import Artist
-from cbook import iterable, is_string_like, is_numlike, ls_mapper, dedent
+from cbook import iterable, is_string_like, is_numlike, ls_mapper, dedent,\
+flatten
 from colors import colorConverter
 from path import Path
 from transforms import Affine2D, Bbox, TransformedPath, IdentityTransform
@@ -76,14 +77,24 @@
 '--' : '_draw_dashed',
 '-.' : '_draw_dash_dot',
 ':'  : '_draw_dotted',
-'steps'  : '_draw_steps_pre',
-'steps-mid'  : '_draw_steps_mid',
-'steps-pre'  : '_draw_steps_pre',
-'steps-post' : '_draw_steps_post',
 'None'   : '_draw_nothing',
 ' '  : '_draw_nothing',
 ''   : '_draw_nothing',
 }
+
+_drawStyles_l = {
+'default': '_draw_lines',
+'steps-mid'  : '_draw_steps_mid',
+'steps-pre'  : '_draw_steps_pre',
+'steps-post' : '_draw_steps_post',
+}
+
+_drawStyles_s = {
+'steps'  : '_draw_steps_pre',
+}
+drawStyles = {}
+drawStyles.update(_drawStyles_l)
+drawStyles.update(_drawStyles_s)
 
 markers = _markers =  {  # hidden names deprecated
 '.'  : '_draw_point',
@@ -155,6 +166,7 @@
  dash_joinstyle  = None,
  solid_joinstyle = None,
  pickradius  = 5,
+ drawstyle   = None,
  **kwargs
  ):
 """
@@ -185,6 +197,8 @@
 if solid_capstyle is None : solid_capstyle=rcParams['lines.solid_capstyle']
 if solid_joinstyle is None : solid_joinstyle=rcParams['lines.solid_joinstyle']
 
+if drawstyle is None : drawstyle='default'
+
 self.set_dash_capstyle(dash_capstyle)
 self.set_dash_joinstyle(dash_joinstyle)
 self.set_solid_capstyle(solid_capstyle)
@@ -192,6 +206,7 @@
 
 
 self.set_linestyle(linestyle)
+self.set_drawstyle(drawstyle)
 self.set_linewidth(linewidth)
 self.set_color(color)
 self.set_marker(marker)
@@ -423,8 +438,10 @@
 funcname = self._lineStyles.get(self._linestyle, '_draw_nothing')
 if funcname != '_draw_nothing':
 tpath, affine = self._transformed_path.get_transformed_path_and_affine()
-lineFunc = getattr(self, funcname)
-lineFunc(renderer, gc, tpath, affine.frozen())
+self._lineFunc = getattr(self, funcname)
+funcname = self.drawStyles.get(self._drawstyle, '_draw_lines')
+drawFunc = getattr(self, funcname)
+drawFunc(renderer, gc, tpath, affine.frozen())
 
 if self._marker is not None:
 gc = renderer.new_gc()
@@ -442,6 +459,7 @@
 
 def get_antialiased(self): return self._antialiased
 def get_color(self): return self._color
+def get_drawstyle(self): return self._drawstyle
 def get_linestyle(self): return self._linestyle
 
 def get_linewidth(self): return self._linewidth
@@ -543,6 +561,18 @@
 """
 self._color = color
 
+def set_drawstyle(self, drawstyle):
+"""
+Set the drawstyle of the plot
+
+'default' connects the points with lines. The steps variants
+produce step-plots. 'steps' is equivalent to 'steps-pre' and
+is maintained for backward-compatibility.
+
+ACCEPTS: [ 'default' | 'steps' | 'steps-pre' | 'steps-mid' | 'steps-post' ]
+"""
+self._drawstyle = drawstyle
+
 def set_linewidth(self, w):
 """
 Set the line width in points
@@ -558,8 +588,20 @@
 'steps' is equivalent to 'steps-pre' and is maintained for
 backward-compatibility.
 
-ACCEPTS: [ '-' | '--' | '-.' | ':' | 'steps' | 'steps-pre' | 'steps-mid' | 'steps-post' | 'None' | ' ' | '' ]
+  

[matplotlib-devel] Bug - ylims are reversed

2008-09-22 Thread Conrad B Ammon
I can't figure out sourceforge's interface to submit a ticket, so I'm 
mailing this to the devel list.  That'll give you a sense of my urgency ;- 
)

Subject: Axes Ylims are reversed
Version: 0.98.3

when calling get_xlims(), the values returned are in increasing order: 
[xmin, xmax].  With get_ylims() however, it is reversed.
# make axes in figure, named ax

ax.get_xlims()
>> [-5, 639]
ax.get_ylims()
>> [479.5, -0.5]

ax.set_ylims(ymin, ymax) seems to work, until you use the Image artist. 
The image flips upside down when you do this.

I first noticed it when I called ax.imshow(image) and an image was right 
side up.  When I called set_ylims(ymin, ymax), it flipped upside down.  It 
was rightside up if I called set_ylims(ymax, ymin)

Workaround: simply reverse the limits when using set_lims or get_lims 

Affected:
Images
Axes
Axes documentation (where get_ylims is described as get_ylims(ymin, ymax) 
)

Sorry for not sending this to the right place,
-Conrad Ammon-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


Re: [matplotlib-devel] Bug - ylims are reversed

2008-09-22 Thread Eric Firing
Conrad B Ammon wrote:
> 
> I can't figure out sourceforge's interface to submit a ticket, so I'm 
> mailing this to the devel list.  That'll give you a sense of my urgency 
> ;- )
> 
> Subject: Axes Ylims are reversed
> Version: 0.98.3
> 
> when calling get_xlims(), the values returned are in increasing order: 
> [xmin, xmax].  With get_ylims() however, it is reversed.
> # make axes in figure, named ax
> 
> ax.get_xlims()
>  >> [-5, 639]
> ax.get_ylims()
>  >> [479.5, -0.5]
> 
> ax.set_ylims(ymin, ymax) seems to work, until you use the Image artist. 
>  The image flips upside down when you do this.
> 
> I first noticed it when I called ax.imshow(image) and an image was right 
> side up.  When I called set_ylims(ymin, ymax), it flipped upside down. 
>  It was rightside up if I called set_ylims(ymax, ymin)
> 
> Workaround: simply reverse the limits when using set_lims or get_lims
> 
> Affected:
> Images
> Axes
> Axes documentation (where get_ylims is described as get_ylims(ymin, ymax) )
> 
> Sorry for not sending this to the right place,
> -Conrad Ammon

Conrad,

It is just as well to start out with a mailing list in a case like this.

What you have found is a very confusing aspect of the variable naming 
and the documentation, not a bug in the code itself.  It has always been 
part of the mpl design that set_ylim and set_xlim are really setting the 
  bottom and top values, and the left and right values, in that order, 
and not the min and max.

To compound the confusion, images are inverted by default; row number 
increases from top to bottom.

See also the methods invert_yaxis, set_ybound, etc.

Eric

-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel