views:

152

answers:

1

So, it seems one cannot do the following (it raises an error, since axes does not have a set_linewidth method):

axes_style = {'linewidth':5}
axes_rect = [0.1, 0.1, 0.9, 0.9]

axes(axes_rect, **axes_style)

and has to use the following old trick instead:

rcParams['axes.linewidth'] = 5 # set the value globally

... # some code

rcdefaults() # restore [global] defaults

Is there an easy / clean way (may be one can set x- and y- axes parameters individually, etc)?

P.S. If no, why?

+3  A: 

Yes, there's an easy and clean way to do this.

Calling 'axhline' and 'axvline' from an axis instance appears to be the technique endorsed in the MPL Documentation.

In any event, it is simple and gives you fine-grained control over the appearance of the axes.

So for instance, this code will create a plot and color the x-axis green and increase the line width of the x-axis from a default value of "1" to a value of "4"; the y-axis is colored red and the line width of the y-axis is increased from "1" to "8".

from matplotlib import pyplot as PLT
fig = PLT.figure()
ax1 = fig.add_subplot(111)

ax1.axhline(linewidth=4, color="g")        # inc. width of x-axis and color it green
ax1.axvline(linewidth=4, color="r")        # inc. width of y-axis and color it red

PLT.show()

The axhline/axvline function accepts additional arguments which ought to allow you do any pretty much whatever you want aesthetically, in particular any of the ~matplotlib.lines.Line2D properties are valid kwargs (e.g., 'alpha', 'linestyle', capstyle, joinstyle).

doug
Thanks a lot, I'll give it a closer look in couple hours.
mlvljr
Thanks again, accepted.
mlvljr
Пожалуйста! Always nice to meet fellow Russian coders.
doug
Is that MC foreign language training, btw? :)
mlvljr