From: John H. <jdh...@ac...> - 2004-02-23 17:45:33
|
>>>>> "James" == James Boyle <bo...@ll...> writes: James> I would like to be able to change the width of a line. If James> I just use B/W the use of line widths and styles can James> differentiate a number of lines. Currently, I do this: p = James> plot(datar,-1.0*(pr),'b') p.extend( James> plot(datac,-1.0*(pc),'r--')) p[0].set_linewidth(2) James> p[1].set_linewidth(3) James> Is this the way to do this? or is there something more James> 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) James> It might be useful for the third argument to have color, James> 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. James> I have not been able to figure out how to change the line James> thickness of the axis frame, i.e. the x and y axis James> themselves. There are examples for the grid, if one is James> 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 |