line width adjustments

I would like to be able to change the width of a line. If

    > I just use B/W the use of line widths and styles can
    > differentiate a number of lines. Currently, I do this: p =
    > plot(datar,-1.0*(pr),'b') p.extend(
    > plot(datac,-1.0*(pc),'r--')) p[0].set_linewidth(2)
    > p[1].set_linewidth(3)

    > Is this the way to do this? or is there something more
    > elegant.

I guess beauty is in the eye of the beholder, but I find this more
elegant

   liner, linec = plot(datar, -1.0*pr, 'b',
                       datac, -1.0*pc, 'r--')
   liner.set_linewidth(2)
   linec.set_linewidth(3)

    > It might be useful for the third argument to have color,
    > style and width.

It's certainly doable, but my hesitancy in doing this is that there
are a lot of properties of a line that one could make an argument for
putting in the format string. matthew suggested allowing a label as
in 'r--;red line' (ala octave). Should the alpha property be in
there? My inclination is to follow the python design philosophy of
"one obvious way to do it".

Perhaps a better solution is to allow keyword args to the plot command

  plot(datar, -1.0*pr, 'b',
       linewidth=0.2, label='a red line', alpha=0.2)

This could be extended to handle plot multiple plots with one command
as follows

  plot(x1, y1, 'b', x2, y2, 'r--',
       linewidth=(2,3), label=('a blue line', 'a red line'),
       alpha=(1.0,0.5), antialiased = (True,False))

legend can be altered to use line labels if they exist, so you could
build the legend of this plot just by callinging

  legend()

I find this the kwargs approach a little cleaner than having a
mother-of-all-format-strings.

    > I have not been able to figure out how to change the line
    > thickness of the axis frame, i.e. the x and y axis
    > themselves. There are examples for the grid, if one is
    > used, and the tick marks but not the frame itself.

Just an oversight on my part - I've been adding these neglected
accessor methods as people need them. The axes border is a
patches.Rectangle instance. If you add the following accessor method
to class Axes (on or around line 598)

    def get_frame(self):
        "Return the axes Rectangle frame"
        return self._axesPatch

I just added it to the src tree. You can then control the axes
rectangle as well, as in this example

    from matplotlib.matlab import *
    ax = subplot(111)
    plot([1,2,3])
    frame = ax.get_frame()
    frame.set_linewidth(3.0)
    frame.set_facecolor('r')
    frame.set_edgecolor('y')
    show()

Hope this helps,
JDH

Perhaps a better solution is to allow keyword args to the plot command

  plot(datar, -1.0*pr, 'b',
       linewidth=0.2, label='a red line', alpha=0.2)

This could be extended to handle plot multiple plots with one command
as follows

  plot(x1, y1, 'b', x2, y2, 'r--',
       linewidth=(2,3), label=('a blue line', 'a red line'),
       alpha=(1.0,0.5), antialiased = (True,False))

I strongly agree with the kwargs approach, it makes things clear as to what is being set.

Just an oversight on my part - I've been adding these neglected
accessor methods as people need them. The axes border is a
patches.Rectangle instance. If you add the following accessor method
to class Axes (on or around line 598)

    def get_frame(self):
        "Return the axes Rectangle frame"
        return self._axesPatch

    from matplotlib.matlab import *
    ax = subplot(111)
    plot([1,2,3])
    frame = ax.get_frame()
    frame.set_linewidth(3.0)
    frame.set_facecolor('r')
    frame.set_edgecolor('y')
    show()

I applied this patch and it worked fine. On my Mac I use the PS backend and convert to PDF. With the default frame width (0.5), the frame was not visible using Adobe Reader 6.0. The file printed fine, but the on screen viewing omitted the frame. This might be a personal problem on my setup, but it might be useful if other people have this difficulty. Making the frame width equal to 1 fixes things.

using matplotlib and lovin' it.

Jim

···

On Feb 23, 2004, at 9:16 AM, John Hunter wrote