(no subject)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

(no subject)

Martin Richter
Hello everyone,

when using errorbar() it is possible to change the attributes (linethickness
etc.) with setp(). This works really well.

But on the otherhand when you try to set the attributes within the
errorbar()-command it will not work - see the exapmle below.

Finding this a bit disturbing I took a look at "axes.py" where errorbar() is
placed. I found out that the drawing of those bars and caps (also
just beeing lines) are added to the plot without the "**kwargs".
Credulously and optimistic I just added it there and - of course - got an
errormessage. So I made a copy of kwargs in the method errorbar() and poped
out all the keywords which could be problematic (I only found out 'marker',
'ls' and 'linestyle') by

kwargs_bars = kwargs.copy()         # make copy of kwargs (not only a
                                    # pointer)
if kwargs.has_key('marker'):        # Is the 'marker' keyword given in
                                    # kwargs?
    marker=kwargs_bars.pop('marker')# filter this entry out (would raise
                                    # error "duplicate keyword argument")
if kwargs.has_key('ls'):            # Is the 'ls' keyword given in kwargs?
    marker=kwargs_bars.pop('ls')    # filter this entry out (vlines, hlines
                                    # would not be drawn)
if kwargs.has_key('linestyle'):     # Is the 'linestyle' keyword given
    marker=kwargs_bars.pop('linestyle') # in kwargs?

and then added **kwargs_bars to the following vlines, hlines and plots:

barlines.extend( self.hlines(y, x, left,**kwargs_bars) )
barlines.extend( self.hlines(y, x, right,**kwargs_bars) )
caplines.extend( self.plot(left, y, '|', ms=2*capsize,**kwargs_bars) )
caplines.extend( self.plot(right, y, '|', ms=2*capsize,**kwargs_bars) )
and also for yerr.

Now the example below worked fine.

I'm now thinking of two things - the second one of them beeing a
possible drawback.

 i) I'm not sure if other keywords should also be poped out. I can't imagine
any further problems - but we all know that this means completely
nothing in the wide field of possible errormessages ;-)

ii) Like before you have the ability to set the color of the cap- and
barlines seperatly from the color of the line connecting the points.
The problem mentioned above (you can't change the thickness of the caps and
bars from the errorbar()-command) still persists for 'linestyle'. Therefor
I'm not sure if the confusion existing before is cleared away. Propably not.
Just imagine a user: "I would like to change the style of the bars and caps
to '-.'. Why do I have to use setp() instead of giving it to errorbar()?"

But I hope that the changes in axes.py are helpful.

Bye,
Martin

PS: Would it be more agreeable if I try to create a patch ruther
then sending the codesnippets? If yes: could anyone give me a hint on how
to find information about patches (how t omake them, how to apply
them)?
Thanks!

#-------------------------------------------------------------------------------
"""This little program shows that it makes an enormous difference
   where the properties of the errorbar()-command are set.
   a) within the command errorbar(...)
   b) seperately with an setp() command
"""
from pylab import *

N=20
x = 1.0*arange(N)/(N-1)
yerrors = .02*rand(N)         # errors in y
xerrors = .02*rand(N)         # errors in x
y = exp(-x)                   # plain curve

figure(1)
subplot(121)
print ("Left  : If the features are set with setp() everything works out
fine.")
error_plot_1 = errorbar(x,y, yerr=yerrors,xerr=xerrors,
                      ls='none',ecolor='r')
setp(error_plot_1,linewidth=3,markeredgewidth=2)

subplot(122)
print ("Right : But if one uses the command errorbars() itself not.")
error_plot = errorbar(x,y, yerr=yerrors,xerr=xerrors,
                      ls='none',ecolor='r',
                      linewidth=3,markeredgewidth=2)
show()

--
GMX DSL = Maximale Leistung zum minimalen Preis!
2000 MB nur 2,99, Flatrate ab 4,99 Euro/Monat: http://www.gmx.net/de/go/dsl


-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users