From: Paul I. <piv...@gm...> - 2011-02-28 19:30:22
|
Gökhan Sever, on 2011-02-28 11:32, wrote: > On Mon, Feb 28, 2011 at 10:48 AM, Andrea Crotti > <and...@gm...>wrote: > > > So since I wanted some space on the borders of my graph, I did this > > really extremely convoluted thing, which apparently works... > > I get a 10% more area on each side, but I'm quite sure there's a better > > way to this, right? > > > > I didn't find any function to pass an increment to the size that's why I > > did this mess... > > > > --8<---------------cut here---------------start------------->8--- > > old_axes = plt.axis() > > sizes = old_axes[1] - old_axes[0], old_axes[3] - old_axes[2] > > offset = lambda x: int((float(x) / 10)) > > new_axes = [] > > > > for i in range(len(old_axes)): > > new_val = old_axes[i] + (((-1) ** (i + 1)) * offset(sizes[i % > > 2])) > > new_axes.append(new_val) > > > > plt.axis(new_axes) > > --8<---------------cut here---------------end--------------->8--- > > You can try: > > fig, ax = plt.subplots(1,1) > ax.plot(range(10)) > fig.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=0.95) Hi Andrea, I think Gökhan is pointing out a different feature than the one you want. You seem to want to adjust the x and y limits of the plot to be some fraction larger than the data that's plotted. You can do this with: ax = plt.subplot(111) ax.plot(range(10)) ax.set_ymargin(.2) ax.set_xmargin(.1) # or ax.margins(.1,.2) ax.autoscale() plt.draw() see also the docstring for ax.autoscale_view for more. best, -- Paul Ivanov 314 address only used for lists, off-list direct email at: http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7 |