|
From: Paul I. <piv...@gm...> - 2011-02-08 23:22:37
|
Curiouslearn, on 2011-02-08 15:32, wrote:
> Sorry if the subject line does not use correct terminology. But the
> following explains the question I have:
> Suppose I have the following code:
>
> import matplotlib.pyplot as plt
>
> fig1 = plt.figure()
> ax1 = fig1.add_subplot(1,1,1)
>
> ax1.scatter(xvalues, yvalues)
> ax1.axvline(1.3, color='DarkGreen')
> rect = ax1.patch
> rect.set_facecolor('SteelBlue') #This works
> rect.set_edgecolor('red') # Is it supposed to set the color of the
> border. If so, this DOES NOT work.
> rect.set_linestyle('dashed') # This DOES NOT work.
> rect.set_linewidth(4) # This DOES NOT work.
>
> For the things that do not work, I tried both
>
> plt.show()
>
> and,
>
> plt.savefig('this_figure.pdf')
>
> Why do the things that I have indicated do not work?
>
> My second question is, if I want to have only the x-axis and y-axis
> line (i.e., get rid of the right edge and top edge of the axes frame)
> how do I do it?
The names of the things you want to change are called spines.
You want:
ax1.spines['right'].set_visible(False)
ax1.spines['top'].set_visible(False)
ax1.spines['left'].set_color('red')
ax1.spines['bottom'].set_color('red')
#and so on for .set_linestyle, .set_linewidth
To hide the tickmarks that are right next to the spines, you can
do:
ax1.xaxis.tick_bottom()
ax1.yaxis.tick_left()
and finally, to color the ticks in red as well, do:
ax1.tick_params(color='red')
best,
--
Paul Ivanov
314 address only used for lists, off-list direct email at:
http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7
|